Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
c2ff73ce
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c2ff73ce
编写于
2月 19, 2020
作者:
L
Liang Zhang
提交者:
GitHub
2月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
decouple find RemoveAvailable with SQLStatement (#4370)
上级
ee4d8603
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
122 addition
and
8 deletion
+122
-8
shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dal/dialect/mysql/ShowColumnsStatement.java
...sql/statement/dal/dialect/mysql/ShowColumnsStatement.java
+14
-1
shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dal/dialect/mysql/ShowTableStatusStatement.java
...statement/dal/dialect/mysql/ShowTableStatusStatement.java
+15
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dal/dialect/mysql/ShowTablesStatement.java
.../sql/statement/dal/dialect/mysql/ShowTablesStatement.java
+15
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/core/filler/dal/FromSchemaFiller.java
...ngsphere/sql/parser/core/filler/dal/FromSchemaFiller.java
+44
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/impl/MySQLDALVisitor.java
...ardingsphere/sql/parser/visitor/impl/MySQLDALVisitor.java
+3
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/resources/META-INF/parsing-rule-definition/mysql/filler-rule-definition.xml
.../parsing-rule-definition/mysql/filler-rule-definition.xml
+1
-0
shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/sql/token/generator/generic/RemoveTokenGenerator.java
...ite/sql/token/generator/generic/RemoveTokenGenerator.java
+30
-7
未找到文件。
shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dal/dialect/mysql/ShowColumnsStatement.java
浏览文件 @
c2ff73ce
...
...
@@ -17,8 +17,10 @@
package
org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql
;
import
com.google.common.base.Optional
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.apache.shardingsphere.sql.parser.sql.segment.generic.RemoveAvailable
;
import
org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dal.DALStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.generic.TableSegmentAvailable
;
...
...
@@ -26,9 +28,20 @@ import org.apache.shardingsphere.sql.parser.sql.statement.generic.TableSegmentAv
/**
* Show columns statement.
*/
@Setter
@Getter
@Setter
public
final
class
ShowColumnsStatement
extends
DALStatement
implements
TableSegmentAvailable
{
private
TableSegment
table
;
private
RemoveAvailable
fromSchema
;
/**
* Get from schema.
*
* @return from schema
*/
public
Optional
<
RemoveAvailable
>
getFromSchema
()
{
return
Optional
.
fromNullable
(
fromSchema
);
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dal/dialect/mysql/ShowTableStatusStatement.java
浏览文件 @
c2ff73ce
...
...
@@ -17,10 +17,25 @@
package
org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql
;
import
com.google.common.base.Optional
;
import
lombok.Setter
;
import
org.apache.shardingsphere.sql.parser.sql.segment.generic.RemoveAvailable
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dal.DALStatement
;
/**
* Show table status statement.
*/
@Setter
public
final
class
ShowTableStatusStatement
extends
DALStatement
{
private
RemoveAvailable
fromSchema
;
/**
* Get from schema.
*
* @return from schema
*/
public
Optional
<
RemoveAvailable
>
getFromSchema
()
{
return
Optional
.
fromNullable
(
fromSchema
);
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/dal/dialect/mysql/ShowTablesStatement.java
浏览文件 @
c2ff73ce
...
...
@@ -17,10 +17,25 @@
package
org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql
;
import
com.google.common.base.Optional
;
import
lombok.Setter
;
import
org.apache.shardingsphere.sql.parser.sql.segment.generic.RemoveAvailable
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dal.DALStatement
;
/**
* Show tables statement.
*/
@Setter
public
final
class
ShowTablesStatement
extends
DALStatement
{
private
RemoveAvailable
fromSchema
;
/**
* Get from schema.
*
* @return from schema
*/
public
Optional
<
RemoveAvailable
>
getFromSchema
()
{
return
Optional
.
fromNullable
(
fromSchema
);
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/core/filler/dal/FromSchemaFiller.java
0 → 100644
浏览文件 @
c2ff73ce
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.sql.parser.core.filler.dal
;
import
org.apache.shardingsphere.sql.parser.core.filler.SQLSegmentFiller
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dal.FromSchemaSegment
;
import
org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowColumnsStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowTableStatusStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowTablesStatement
;
/**
* From schema filler.
*/
public
final
class
FromSchemaFiller
implements
SQLSegmentFiller
<
FromSchemaSegment
>
{
@Override
public
void
fill
(
final
FromSchemaSegment
sqlSegment
,
final
SQLStatement
sqlStatement
)
{
if
(
sqlStatement
instanceof
ShowTablesStatement
)
{
((
ShowTablesStatement
)
sqlStatement
).
setFromSchema
(
sqlSegment
);
}
if
(
sqlStatement
instanceof
ShowTableStatusStatement
)
{
((
ShowTableStatusStatement
)
sqlStatement
).
setFromSchema
(
sqlSegment
);
}
if
(
sqlStatement
instanceof
ShowColumnsStatement
)
{
((
ShowColumnsStatement
)
sqlStatement
).
setFromSchema
(
sqlSegment
);
}
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/impl/MySQLDALVisitor.java
浏览文件 @
c2ff73ce
...
...
@@ -89,6 +89,7 @@ public final class MySQLDALVisitor extends MySQLVisitor {
if
(
null
!=
ctx
.
fromSchema
())
{
FromSchemaSegment
fromSchemaSegment
=
(
FromSchemaSegment
)
visit
(
ctx
.
fromSchema
());
result
.
getAllSQLSegments
().
add
(
fromSchemaSegment
);
result
.
setFromSchema
(
fromSchemaSegment
);
}
if
(
null
!=
ctx
.
showLike
())
{
ShowLikeSegment
showLikeSegment
=
(
ShowLikeSegment
)
visit
(
ctx
.
showLike
());
...
...
@@ -103,6 +104,7 @@ public final class MySQLDALVisitor extends MySQLVisitor {
if
(
null
!=
ctx
.
fromSchema
())
{
FromSchemaSegment
fromSchemaSegment
=
(
FromSchemaSegment
)
visit
(
ctx
.
fromSchema
());
result
.
getAllSQLSegments
().
add
(
fromSchemaSegment
);
result
.
setFromSchema
(
fromSchemaSegment
);
}
if
(
null
!=
ctx
.
showLike
())
{
ShowLikeSegment
showLikeSegment
=
(
ShowLikeSegment
)
visit
(
ctx
.
showLike
());
...
...
@@ -123,6 +125,7 @@ public final class MySQLDALVisitor extends MySQLVisitor {
if
(
null
!=
ctx
.
fromSchema
())
{
FromSchemaSegment
fromSchemaSegment
=
(
FromSchemaSegment
)
visit
(
ctx
.
fromSchema
());
result
.
getAllSQLSegments
().
add
(
fromSchemaSegment
);
result
.
setFromSchema
(
fromSchemaSegment
);
}
return
result
;
}
...
...
shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/resources/META-INF/parsing-rule-definition/mysql/filler-rule-definition.xml
浏览文件 @
c2ff73ce
...
...
@@ -18,4 +18,5 @@
<filler-rule-definition>
<filler-rule
sql-segment-class=
"org.apache.shardingsphere.sql.parser.sql.segment.tcl.AutoCommitSegment"
filler-class=
"org.apache.shardingsphere.sql.parser.core.filler.tcl.MySQLAutoCommitFiller"
/>
<filler-rule
sql-segment-class=
"org.apache.shardingsphere.sql.parser.sql.segment.dal.FromSchemaSegment"
filler-class=
"org.apache.shardingsphere.sql.parser.core.filler.dal.FromSchemaFiller"
/>
</filler-rule-definition>
shardingsphere-underlying/shardingsphere-rewrite/shardingsphere-rewrite-engine/src/main/java/org/apache/shardingsphere/underlying/rewrite/sql/token/generator/generic/RemoveTokenGenerator.java
浏览文件 @
c2ff73ce
...
...
@@ -17,14 +17,17 @@
package
org.apache.shardingsphere.underlying.rewrite.sql.token.generator.generic
;
import
com.google.common.base.Preconditions
;
import
org.apache.shardingsphere.sql.parser.relation.statement.SQLStatementContext
;
import
org.apache.shardingsphere.sql.parser.sql.segment.SQLSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.generic.RemoveAvailable
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowColumnsStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowTableStatusStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowTablesStatement
;
import
org.apache.shardingsphere.underlying.rewrite.sql.token.generator.CollectionSQLTokenGenerator
;
import
org.apache.shardingsphere.underlying.rewrite.sql.token.pojo.generic.RemoveToken
;
import
java.util.Collection
;
import
java.util.
LinkedList
;
import
java.util.
Collections
;
/**
* Remove token generator.
...
...
@@ -33,15 +36,35 @@ public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator {
@Override
public
boolean
isGenerateSQLToken
(
final
SQLStatementContext
sqlStatementContext
)
{
return
!
sqlStatementContext
.
getSqlStatement
().
findSQLSegments
(
RemoveAvailable
.
class
).
isEmpty
();
if
(
sqlStatementContext
.
getSqlStatement
()
instanceof
ShowTablesStatement
)
{
return
((
ShowTablesStatement
)
sqlStatementContext
.
getSqlStatement
()).
getFromSchema
().
isPresent
();
}
if
(
sqlStatementContext
.
getSqlStatement
()
instanceof
ShowTableStatusStatement
)
{
return
((
ShowTableStatusStatement
)
sqlStatementContext
.
getSqlStatement
()).
getFromSchema
().
isPresent
();
}
if
(
sqlStatementContext
.
getSqlStatement
()
instanceof
ShowColumnsStatement
)
{
return
((
ShowColumnsStatement
)
sqlStatementContext
.
getSqlStatement
()).
getFromSchema
().
isPresent
();
}
return
false
;
}
@Override
public
Collection
<
RemoveToken
>
generateSQLTokens
(
final
SQLStatementContext
sqlStatementContext
)
{
Collection
<
RemoveToken
>
result
=
new
LinkedList
<>();
for
(
SQLSegment
each
:
sqlStatementContext
.
getSqlStatement
().
findSQLSegments
(
RemoveAvailable
.
class
))
{
result
.
add
(
new
RemoveToken
(
each
.
getStartIndex
(),
each
.
getStopIndex
()));
if
(
sqlStatementContext
.
getSqlStatement
()
instanceof
ShowTablesStatement
)
{
Preconditions
.
checkState
(((
ShowTablesStatement
)
sqlStatementContext
.
getSqlStatement
()).
getFromSchema
().
isPresent
());
RemoveAvailable
removeAvailable
=
((
ShowTablesStatement
)
sqlStatementContext
.
getSqlStatement
()).
getFromSchema
().
get
();
return
Collections
.
singletonList
(
new
RemoveToken
(
removeAvailable
.
getStartIndex
(),
removeAvailable
.
getStopIndex
()));
}
if
(
sqlStatementContext
.
getSqlStatement
()
instanceof
ShowTableStatusStatement
)
{
Preconditions
.
checkState
(((
ShowTableStatusStatement
)
sqlStatementContext
.
getSqlStatement
()).
getFromSchema
().
isPresent
());
RemoveAvailable
removeAvailable
=
((
ShowTableStatusStatement
)
sqlStatementContext
.
getSqlStatement
()).
getFromSchema
().
get
();
return
Collections
.
singletonList
(
new
RemoveToken
(
removeAvailable
.
getStartIndex
(),
removeAvailable
.
getStopIndex
()));
}
if
(
sqlStatementContext
.
getSqlStatement
()
instanceof
ShowColumnsStatement
)
{
Preconditions
.
checkState
(((
ShowColumnsStatement
)
sqlStatementContext
.
getSqlStatement
()).
getFromSchema
().
isPresent
());
RemoveAvailable
removeAvailable
=
((
ShowColumnsStatement
)
sqlStatementContext
.
getSqlStatement
()).
getFromSchema
().
get
();
return
Collections
.
singletonList
(
new
RemoveToken
(
removeAvailable
.
getStartIndex
(),
removeAvailable
.
getStopIndex
()));
}
return
result
;
return
Collections
.
emptyList
()
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录