Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
2a14ec65
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
2a14ec65
编写于
10月 28, 2020
作者:
J
JingShang Lu
提交者:
GitHub
10月 28, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve the definition of select (#7938)
* Improve the definition of select * fix
上级
2c29075d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
153 addition
and
69 deletion
+153
-69
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
...ql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
+4
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
...arser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
+1
-1
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
...arser-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
+66
-17
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
...arser-mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
+3
-3
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
...ysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
+79
-48
未找到文件。
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/BaseRule.g4
浏览文件 @
2a14ec65
...
...
@@ -648,3 +648,7 @@ cursorName
conditionName
: identifier
;
unionOption
: ALL | DISTINCT
;
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DALStatement.g4
浏览文件 @
2a14ec65
...
...
@@ -381,7 +381,7 @@ explainType
;
explainableStatement
: select |
tableStatement |
delete | insert | replace | update
: select | delete | insert | replace | update
;
formatName
...
...
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/DMLStatement.g4
浏览文件 @
2a14ec65
...
...
@@ -105,15 +105,46 @@ singleTableClause
;
multipleTablesClause
:
multipleTableNames FROM tableReferences | FROM multipleTableNames
USING tableReferences
:
tableAliasRefList FROM tableReferences | FROM tableAliasRefList
USING tableReferences
;
multipleTableNames
: tableName DOT_ASTERISK_? (COMMA_ tableName DOT_ASTERISK_?)*
;
select
: withClause? unionClause
select
: queryExpression lockClauseList?
| queryExpressionParens
| selectWithInto
;
selectWithInto
: LP_ selectWithInto RP_
| queryExpression selectIntoExpression lockClauseList?
| queryExpression lockClauseList selectIntoExpression
;
queryExpression
: withClause? (queryExpressionBody | queryExpressionParens) orderByClause? limitClause?
;
queryExpressionBody
: queryPrimary
| queryExpressionParens UNION unionOption? (queryPrimary | queryExpressionParens)
;
queryExpressionParens
: LP_ (queryExpressionParens | queryExpression lockClauseList?) RP_
;
queryPrimary
: querySpecification
| tableValueConstructor
| explicitTable
;
querySpecification
: SELECT selectSpecification* projections selectIntoExpression? fromClause? whereClause? groupByClause? havingClause? windowClause?
;
call
...
...
@@ -177,12 +208,12 @@ loadXmlStatement
(setAssignmentsClause)?
;
tableStatement
: TABLE tableName
(ORDER BY columnName)? (LIMIT NUMBER_ (OFFSET NUMBER_)?)?
explicitTable
: TABLE tableName
;
valuesStatement
: VALUES rowConstructorList
(ORDER BY columnDesignator)? (LIMIT BY NUMBER_)?
tableValueConstructor
: VALUES rowConstructorList
;
columnDesignator
...
...
@@ -201,14 +232,6 @@ cteClause
: ignoredIdentifier columnNames? AS subquery
;
unionClause
: selectClause (UNION (ALL | DISTINCT)? selectClause)*
;
selectClause
: LP_? SELECT selectSpecification* projections selectIntoExpression? fromClause? whereClause? groupByClause? havingClause? windowClause? orderByClause? limitClause? selectIntoExpression? lockClause? RP_?
;
selectSpecification
: duplicateSpecification | HIGH_PRIORITY | STRAIGHT_JOIN | SQL_SMALL_RESULT | SQL_BIG_RESULT | SQL_BUFFER_RESULT | (SQL_CACHE | SQL_NO_CACHE) | SQL_CALC_FOUND_ROWS
;
...
...
@@ -308,7 +331,7 @@ windowItem
;
subquery
:
LP_ unionClause RP_
:
queryExpressionParens
;
selectLinesInto
...
...
@@ -325,5 +348,31 @@ selectIntoExpression
;
lockClause
: FOR UPDATE | LOCK IN SHARE MODE
: FOR lockStrength lockedRowAction?
| FOR lockStrength
| LOCK IN SHARE MODE
;
lockClauseList
: lockClause+
;
lockStrength
: UPDATE | SHARE
;
lockedRowAction
: SKIP_SYMBOL LOCKED | NOWAIT
;
tableLockingList
: OF tableAliasRefList
;
tableIdentOptWild
: tableName DOT_ASTERISK_?
;
tableAliasRefList
: tableIdentOptWild+
;
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/antlr4/imports/mysql/MySQLKeyword.g4
浏览文件 @
2a14ec65
...
...
@@ -2259,9 +2259,9 @@ SIMPLE
: S I M P L E
;
//SKIP
//
: S K I P
//
;
SKIP_SYMBOL
: S K I P
;
SLAVE
: S L A V E
...
...
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLStatementSQLVisitor.java
浏览文件 @
2a14ec65
...
...
@@ -498,9 +498,72 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
@Override
public
ASTNode
visitSubquery
(
final
SubqueryContext
ctx
)
{
return
visit
(
ctx
.
unionClause
());
return
visit
(
ctx
.
queryExpressionParens
());
}
@Override
public
ASTNode
visitQueryExpressionParens
(
final
MySQLStatementParser
.
QueryExpressionParensContext
ctx
)
{
if
(
null
!=
ctx
.
queryExpressionParens
())
{
return
visit
(
ctx
.
queryExpressionParens
());
}
MySQLSelectStatement
result
=
(
MySQLSelectStatement
)
visit
(
ctx
.
queryExpression
());
if
(
null
!=
ctx
.
lockClauseList
())
{
result
.
setLock
((
LockSegment
)
visit
(
ctx
.
lockClauseList
()));
}
result
.
setParameterCount
(
getCurrentParameterIndex
());
return
result
;
}
@Override
public
ASTNode
visitLockClauseList
(
final
MySQLStatementParser
.
LockClauseListContext
ctx
)
{
return
new
LockSegment
(
ctx
.
getStart
().
getStartIndex
(),
ctx
.
getStop
().
getStopIndex
());
}
@Override
public
ASTNode
visitQueryExpression
(
final
MySQLStatementParser
.
QueryExpressionContext
ctx
)
{
MySQLSelectStatement
result
;
if
(
null
!=
ctx
.
queryExpressionBody
())
{
result
=
(
MySQLSelectStatement
)
visit
(
ctx
.
queryExpressionBody
());
}
else
{
result
=
(
MySQLSelectStatement
)
visit
(
ctx
.
queryExpressionParens
());
}
if
(
null
!=
ctx
.
orderByClause
())
{
result
.
setOrderBy
((
OrderBySegment
)
visit
(
ctx
.
orderByClause
()));
}
if
(
null
!=
ctx
.
limitClause
())
{
result
.
setLimit
((
LimitSegment
)
visit
(
ctx
.
limitClause
()));
}
return
result
;
}
@Override
public
ASTNode
visitQueryExpressionBody
(
final
MySQLStatementParser
.
QueryExpressionBodyContext
ctx
)
{
if
(
1
==
ctx
.
getChildCount
()
&&
ctx
.
getChild
(
0
)
instanceof
MySQLStatementParser
.
QueryPrimaryContext
)
{
return
visit
(
ctx
.
queryPrimary
());
}
throw
new
IllegalStateException
(
"union select is not supported yet."
);
}
@Override
public
ASTNode
visitQuerySpecification
(
final
MySQLStatementParser
.
QuerySpecificationContext
ctx
)
{
MySQLSelectStatement
result
=
new
MySQLSelectStatement
();
result
.
setProjections
((
ProjectionsSegment
)
visit
(
ctx
.
projections
()));
if
(
null
!=
ctx
.
selectSpecification
())
{
result
.
getProjections
().
setDistinctRow
(
isDistinct
(
ctx
));
}
if
(
null
!=
ctx
.
fromClause
())
{
TableSegment
tableSource
=
(
TableSegment
)
visit
(
ctx
.
fromClause
().
tableReferences
());
result
.
setFrom
(
tableSource
);
}
if
(
null
!=
ctx
.
whereClause
())
{
result
.
setWhere
((
WhereSegment
)
visit
(
ctx
.
whereClause
()));
}
if
(
null
!=
ctx
.
groupByClause
())
{
result
.
setGroupBy
((
GroupBySegment
)
visit
(
ctx
.
groupByClause
()));
}
return
result
;
}
@Override
public
final
ASTNode
visitIntervalExpression
(
final
IntervalExpressionContext
ctx
)
{
calculateParameterCount
(
Collections
.
singleton
(
ctx
.
intervalValue
().
expr
()));
...
...
@@ -950,14 +1013,14 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
DeleteMultiTableSegment
result
=
new
DeleteMultiTableSegment
();
TableSegment
relateTableSource
=
(
TableSegment
)
visit
(
ctx
.
tableReferences
());
result
.
setRelationTable
(
relateTableSource
);
result
.
setActualDeleteTables
(
generateTablesFromTableMultipleTableNames
(
ctx
.
multipleTableNames
()));
result
.
setActualDeleteTables
(
generateTablesFromTableMultipleTableNames
(
ctx
.
tableAliasRefList
()));
return
result
;
}
private
List
<
SimpleTableSegment
>
generateTablesFromTableMultipleTableNames
(
final
MySQLStatementParser
.
MultipleTableNames
Context
ctx
)
{
private
List
<
SimpleTableSegment
>
generateTablesFromTableMultipleTableNames
(
final
MySQLStatementParser
.
TableAliasRefList
Context
ctx
)
{
List
<
SimpleTableSegment
>
result
=
new
LinkedList
<>();
for
(
TableNameContext
each
:
ctx
.
tableName
())
{
result
.
add
((
SimpleTableSegment
)
visit
(
each
));
for
(
MySQLStatementParser
.
TableIdentOptWildContext
each
:
ctx
.
tableIdentOptWild
())
{
result
.
add
((
SimpleTableSegment
)
visit
(
each
.
tableName
()
));
}
return
result
;
}
...
...
@@ -965,47 +1028,20 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
@Override
public
ASTNode
visitSelect
(
final
MySQLStatementParser
.
SelectContext
ctx
)
{
// TODO :Unsupported for withClause.
MySQLSelectStatement
result
=
(
MySQLSelectStatement
)
visit
(
ctx
.
unionClause
());
result
.
setParameterCount
(
getCurrentParameterIndex
());
return
result
;
}
@Override
public
ASTNode
visitUnionClause
(
final
MySQLStatementParser
.
UnionClauseContext
ctx
)
{
// TODO :Unsupported for union SQL.
return
visit
(
ctx
.
selectClause
(
0
));
}
@Override
public
ASTNode
visitSelectClause
(
final
MySQLStatementParser
.
SelectClauseContext
ctx
)
{
MySQLSelectStatement
result
=
new
MySQLSelectStatement
();
result
.
setProjections
((
ProjectionsSegment
)
visit
(
ctx
.
projections
()));
if
(
null
!=
ctx
.
selectSpecification
())
{
result
.
getProjections
().
setDistinctRow
(
isDistinct
(
ctx
));
}
if
(
null
!=
ctx
.
fromClause
())
{
TableSegment
tableSource
=
(
TableSegment
)
visit
(
ctx
.
fromClause
().
tableReferences
());
result
.
setFrom
(
tableSource
);
}
if
(
null
!=
ctx
.
whereClause
())
{
result
.
setWhere
((
WhereSegment
)
visit
(
ctx
.
whereClause
()));
}
if
(
null
!=
ctx
.
groupByClause
())
{
result
.
setGroupBy
((
GroupBySegment
)
visit
(
ctx
.
groupByClause
()));
}
if
(
null
!=
ctx
.
orderByClause
())
{
result
.
setOrderBy
((
OrderBySegment
)
visit
(
ctx
.
orderByClause
()));
}
if
(
null
!=
ctx
.
limitClause
())
{
result
.
setLimit
((
LimitSegment
)
visit
(
ctx
.
limitClause
()));
}
if
(
null
!=
ctx
.
lockClause
())
{
result
.
setLock
((
LockSegment
)
visit
(
ctx
.
lockClause
()));
MySQLSelectStatement
result
;
if
(
null
!=
ctx
.
queryExpression
())
{
result
=
(
MySQLSelectStatement
)
visit
(
ctx
.
queryExpression
());
if
(
null
!=
ctx
.
lockClauseList
())
{
result
.
setLock
((
LockSegment
)
visit
(
ctx
.
lockClauseList
()));
}
}
else
{
result
=
(
MySQLSelectStatement
)
visit
(
ctx
.
getChild
(
0
));
}
result
.
setParameterCount
(
getCurrentParameterIndex
());
return
result
;
}
private
boolean
isDistinct
(
final
MySQLStatementParser
.
SelectClause
Context
ctx
)
{
private
boolean
isDistinct
(
final
MySQLStatementParser
.
QuerySpecification
Context
ctx
)
{
for
(
MySQLStatementParser
.
SelectSpecificationContext
each
:
ctx
.
selectSpecification
())
{
if
(((
BooleanLiteralValue
)
visit
(
each
)).
getValue
())
{
return
true
;
...
...
@@ -1258,9 +1294,4 @@ public abstract class MySQLStatementSQLVisitor extends MySQLStatementBaseVisitor
}
return
new
ParameterMarkerLimitValueSegment
(
ctx
.
getStart
().
getStartIndex
(),
ctx
.
getStop
().
getStopIndex
(),
((
ParameterMarkerValue
)
visit
(
ctx
.
parameterMarker
())).
getValue
());
}
@Override
public
ASTNode
visitLockClause
(
final
MySQLStatementParser
.
LockClauseContext
ctx
)
{
return
new
LockSegment
(
ctx
.
getStart
().
getStartIndex
(),
ctx
.
getStop
().
getStopIndex
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录