Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
e7340f90
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,发现更多精彩内容 >>
提交
e7340f90
编写于
2月 10, 2020
作者:
J
Juan Pan(Trista)
提交者:
GitHub
2月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support using limit pagination (#4222)
* add more tests for order-by and or sql * support using limit pagination
上级
0d5bdd22
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
1225 addition
and
1 deletion
+1225
-1
shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/MySQLDMLVisitor.java
...he/shardingsphere/sql/parser/visitor/MySQLDMLVisitor.java
+46
-1
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/visitor/dml/select-or.xml
...-parser-test/src/test/resources/visitor/dml/select-or.xml
+397
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/visitor/dml/select-order-by.xml
...r-test/src/test/resources/visitor/dml/select-order-by.xml
+243
-0
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/visitor/dml/select-pagination.xml
...test/src/test/resources/visitor/dml/select-pagination.xml
+539
-0
未找到文件。
shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/visitor/MySQLDMLVisitor.java
浏览文件 @
e7340f90
...
...
@@ -31,6 +31,9 @@ import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FromCla
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.InsertContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.InsertValuesClauseContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.JoinedTableContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LimitClauseContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LimitOffsetContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LimitRowCountContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.MultipleTableNamesContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.MultipleTablesClauseContext
;
import
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OnDuplicateKeyClauseContext
;
...
...
@@ -65,6 +68,10 @@ import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionSegme
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionsSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ShorthandProjectionSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.order.OrderBySegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.PaginationValueSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.limit.LimitSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.AndPredicate
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.OrPredicateSegment
;
import
org.apache.shardingsphere.sql.parser.sql.segment.dml.predicate.PredicateSegment
;
...
...
@@ -74,9 +81,11 @@ import org.apache.shardingsphere.sql.parser.sql.statement.dml.DeleteStatement;
import
org.apache.shardingsphere.sql.parser.sql.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.sql.parser.sql.statement.dml.UpdateStatement
;
import
org.apache.shardingsphere.sql.parser.sql.value.literal.impl.BooleanLiteralValue
;
import
org.apache.shardingsphere.sql.parser.sql.value.collection.CollectionValue
;
import
org.apache.shardingsphere.sql.parser.sql.value.literal.impl.BooleanLiteralValue
;
import
org.apache.shardingsphere.sql.parser.sql.value.literal.impl.NumberLiteralValue
;
import
org.apache.shardingsphere.sql.parser.sql.value.literal.impl.StringLiteralValue
;
import
org.apache.shardingsphere.sql.parser.sql.value.parametermarker.ParameterMarkerValue
;
import
java.util.Collection
;
import
java.util.LinkedList
;
...
...
@@ -285,6 +294,9 @@ public final class MySQLDMLVisitor extends MySQLVisitor {
result
.
setOrderBy
(
orderBy
);
result
.
getAllSQLSegments
().
add
(
orderBy
);
}
if
(
null
!=
ctx
.
limitClause
())
{
result
.
getAllSQLSegments
().
add
((
LimitSegment
)
visit
(
ctx
.
limitClause
()));
}
return
result
;
}
...
...
@@ -436,4 +448,37 @@ public final class MySQLDMLVisitor extends MySQLVisitor {
result
.
setParametersCount
(
getCurrentParameterIndex
());
return
result
;
}
@Override
public
ASTNode
visitLimitClause
(
final
LimitClauseContext
ctx
)
{
if
(
null
==
ctx
.
limitOffset
())
{
return
new
LimitSegment
(
ctx
.
start
.
getStartIndex
(),
ctx
.
stop
.
getStopIndex
(),
null
,
(
PaginationValueSegment
)
visit
(
ctx
.
limitRowCount
()));
}
PaginationValueSegment
rowCount
;
PaginationValueSegment
limitOffset
;
if
(
null
!=
ctx
.
OFFSET
())
{
rowCount
=
(
PaginationValueSegment
)
visit
(
ctx
.
limitRowCount
());
limitOffset
=
(
PaginationValueSegment
)
visit
(
ctx
.
limitOffset
());
}
else
{
limitOffset
=
(
PaginationValueSegment
)
visit
(
ctx
.
limitOffset
());
rowCount
=
(
PaginationValueSegment
)
visit
(
ctx
.
limitRowCount
());
}
return
new
LimitSegment
(
ctx
.
start
.
getStartIndex
(),
ctx
.
stop
.
getStopIndex
(),
limitOffset
,
rowCount
);
}
@Override
public
ASTNode
visitLimitRowCount
(
final
LimitRowCountContext
ctx
)
{
if
(
null
!=
ctx
.
numberLiterals
())
{
return
new
NumberLiteralLimitValueSegment
(
ctx
.
start
.
getStartIndex
(),
ctx
.
stop
.
getStopIndex
(),
((
NumberLiteralValue
)
visit
(
ctx
.
numberLiterals
())).
getValue
().
longValue
());
}
return
new
ParameterMarkerLimitValueSegment
(
ctx
.
start
.
getStartIndex
(),
ctx
.
stop
.
getStopIndex
(),
((
ParameterMarkerValue
)
visit
(
ctx
.
parameterMarker
())).
getValue
());
}
@Override
public
ASTNode
visitLimitOffset
(
final
LimitOffsetContext
ctx
)
{
if
(
null
!=
ctx
.
numberLiterals
())
{
return
new
NumberLiteralLimitValueSegment
(
ctx
.
start
.
getStartIndex
(),
ctx
.
stop
.
getStopIndex
(),
((
NumberLiteralValue
)
visit
(
ctx
.
numberLiterals
())).
getValue
().
longValue
());
}
return
new
ParameterMarkerLimitValueSegment
(
ctx
.
start
.
getStartIndex
(),
ctx
.
stop
.
getStopIndex
(),
((
ParameterMarkerValue
)
visit
(
ctx
.
parameterMarker
())).
getValue
());
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/visitor/dml/select-or.xml
0 → 100644
浏览文件 @
e7340f90
此差异已折叠。
点击以展开。
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/visitor/dml/select-order-by.xml
0 → 100644
浏览文件 @
e7340f90
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<sql-parser-test-cases>
<select
sql-case-id=
"select_order_by_asc_and_index_desc"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"14"
stop-index=
"20"
/>
<projections
start-index=
"7"
stop-index=
"7"
>
<shorthand-projection
start-index=
"7"
stop-index=
"7"
/>
</projections>
<order-by>
<column-item
name=
"order_id"
>
<owner
name=
"o"
start-index=
"33"
stop-index=
"33"
/>
</column-item>
<index-item
index=
"2"
order-direction=
"DESC"
/>
</order-by>
</select>
<select
sql-case-id=
"select_order_by_desc_and_index_asc"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"16"
stop-index=
"22"
/>
<table
name=
"t_order_item"
alias=
"i"
start-index=
"27"
stop-index=
"38"
/>
<projections
start-index=
"7"
stop-index=
"9"
>
<shorthand-projection
start-index=
"7"
stop-index=
"9"
>
<owner
name=
"i"
start-index=
"7"
stop-index=
"7"
/>
</shorthand-projection>
</projections>
<where
parameters-count=
"0"
start-index=
"42"
stop-index=
"92"
>
<and-predicate>
<predicate
start-index=
"48"
stop-index=
"70"
>
<column-left-value
name=
"order_id"
start-index=
"48"
stop-index=
"57"
>
<owner
name=
"o"
start-index=
"48"
stop-index=
"48"
/>
</column-left-value>
<operator
type=
"="
/>
<column-right-value
name=
"order_id"
start-index=
"61"
stop-index=
"70"
>
<owner
name=
"i"
start-index=
"61"
stop-index=
"61"
/>
</column-right-value>
</predicate>
<predicate
start-index=
"76"
stop-index=
"92"
>
<column-left-value
name=
"status"
start-index=
"76"
stop-index=
"83"
>
<owner
name=
"o"
start-index=
"76"
stop-index=
"76"
/>
</column-left-value>
<operator
type=
"="
/>
<compare-right-value>
<parameter-marker-expression
value=
"0"
/>
<literal-expression
value=
"init"
/>
</compare-right-value>
</predicate>
</and-predicate>
</where>
<order-by>
<column-item
name=
"order_id"
order-direction=
"DESC"
>
<owner
name=
"o"
start-index=
"103"
stop-index=
"103"
/>
</column-item>
<index-item
index=
"1"
/>
</order-by>
</select>
<select
sql-case-id=
"select_order_by_with_ordered_column"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"40"
stop-index=
"46"
/>
<projections
start-index=
"7"
stop-index=
"33"
>
<column-projection
name=
"order_id"
alias=
"gen_order_id_"
start-index=
"7"
stop-index=
"16"
>
<owner
name=
"o"
start-index=
"7"
stop-index=
"7"
/>
</column-projection>
</projections>
<order-by>
<column-item
name=
"order_id"
>
<owner
name=
"o"
start-index=
"59"
stop-index=
"59"
/>
</column-item>
</order-by>
</select>
<select
sql-case-id=
"select_order_by_with_date"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"16"
stop-index=
"22"
/>
<table
name=
"t_order_item"
alias=
"i"
start-index=
"27"
stop-index=
"38"
/>
<projections
start-index=
"7"
stop-index=
"9"
>
<shorthand-projection
start-index=
"7"
stop-index=
"9"
>
<owner
name=
"i"
start-index=
"7"
stop-index=
"7"
/>
</shorthand-projection>
</projections>
<where
parameters-count=
"0"
start-index=
"42"
stop-index=
"92"
>
<and-predicate>
<predicate
start-index=
"48"
stop-index=
"70"
>
<column-left-value
name=
"order_id"
start-index=
"48"
stop-index=
"57"
>
<owner
name=
"o"
start-index=
"48"
stop-index=
"48"
/>
</column-left-value>
<operator
type=
"="
/>
<column-right-value
name=
"order_id"
start-index=
"61"
stop-index=
"70"
>
<owner
name=
"i"
start-index=
"61"
stop-index=
"61"
/>
</column-right-value>
</predicate>
<predicate
start-index=
"76"
stop-index=
"92"
>
<column-left-value
name=
"status"
start-index=
"76"
stop-index=
"83"
>
<owner
name=
"o"
start-index=
"76"
stop-index=
"76"
/>
</column-left-value>
<operator
type=
"="
/>
<compare-right-value>
<literal-expression
value=
"init"
/>
</compare-right-value>
</predicate>
</and-predicate>
</where>
<order-by>
<column-item
name=
"creation_date"
order-direction=
"DESC"
>
<owner
name=
"i"
start-index=
"103"
stop-index=
"103"
/>
</column-item>
<column-item
name=
"order_id"
order-direction=
"DESC"
>
<owner
name=
"o"
start-index=
"125"
stop-index=
"125"
/>
</column-item>
<column-item
name=
"item_id"
>
<owner
name=
"i"
start-index=
"142"
stop-index=
"142"
/>
</column-item>
</order-by>
</select>
<!-- //TODO add order-by-null-type -->
<select
sql-case-id=
"select_order_by_for_nulls_first"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"40"
stop-index=
"46"
/>
<projections
start-index=
"7"
stop-index=
"33"
>
<column-projection
name=
"order_id"
alias=
"gen_order_id_"
start-index=
"7"
stop-index=
"16"
>
<owner
name=
"o"
start-index=
"7"
stop-index=
"7"
/>
</column-projection>
</projections>
<order-by>
<column-item
name=
"order_id"
>
<owner
name=
"o"
start-index=
"59"
stop-index=
"59"
/>
</column-item>
</order-by>
</select>
<!-- //TODO add order-by-null-type -->
<select
sql-case-id=
"select_order_by_for_nulls_last"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"40"
stop-index=
"46"
/>
<projections
start-index=
"7"
stop-index=
"33"
>
<column-projection
name=
"order_id"
alias=
"gen_order_id_"
start-index=
"7"
stop-index=
"16"
>
<owner
name=
"o"
start-index=
"7"
stop-index=
"7"
/>
</column-projection>
</projections>
<order-by>
<column-item
name=
"order_id"
>
<owner
name=
"o"
start-index=
"59"
stop-index=
"59"
/>
</column-item>
</order-by>
</select>
<select
sql-case-id=
"select_order_by_with_multiple_stars"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"29"
stop-index=
"35"
/>
<projections
start-index=
"7"
stop-index=
"22"
>
<shorthand-projection
start-index=
"7"
stop-index=
"7"
/>
<shorthand-projection
start-index=
"20"
stop-index=
"22"
>
<owner
name=
"o"
start-index=
"20"
stop-index=
"20"
/>
</shorthand-projection>
<column-projection
name=
"order_id"
start-index=
"10"
stop-index=
"17"
/>
</projections>
<order-by>
<column-item
name=
"order_id"
>
<owner
name=
"o"
start-index=
"48"
stop-index=
"48"
/>
</column-item>
</order-by>
</select>
<select
sql-case-id=
"select_order_by_with_alias_star_alias_name"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"16"
stop-index=
"22"
/>
<projections
start-index=
"7"
stop-index=
"9"
>
<shorthand-projection
start-index=
"7"
stop-index=
"9"
>
<owner
name=
"o"
start-index=
"7"
stop-index=
"7"
/>
</shorthand-projection>
</projections>
<order-by>
<column-item
name=
"order_id"
>
<owner
name=
"o"
start-index=
"35"
stop-index=
"35"
/>
</column-item>
</order-by>
</select>
<select
sql-case-id=
"select_order_by_with_star_table_alias"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"14"
stop-index=
"20"
/>
<projections
start-index=
"7"
stop-index=
"7"
>
<shorthand-projection
start-index=
"7"
stop-index=
"7"
/>
</projections>
<order-by>
<column-item
name=
"order_id"
/>
</order-by>
</select>
<!--TODO need to add later-->
<!--<select sql-case-id="select_order_by_with_parameter" parameters="order_id">-->
<!--<table name="t_order" alias="o" start-index="14" stop-index="20" />-->
<!--</select>-->
<select
sql-case-id=
"select_order_by_with_table_star_table_name"
>
<table
name=
"t_order"
start-index=
"22"
stop-index=
"28"
/>
<projections
start-index=
"7"
stop-index=
"15"
>
<shorthand-projection
start-index=
"7"
stop-index=
"15"
>
<owner
name=
"t_order"
start-index=
"7"
stop-index=
"13"
/>
</shorthand-projection>
</projections>
<order-by>
<column-item
name=
"order_id"
>
<owner
name=
"t_order"
start-index=
"39"
stop-index=
"45"
/>
</column-item>
</order-by>
</select>
<select
sql-case-id=
"select_order_by_with_star_no_table_alias"
>
<table
name=
"t_order"
start-index=
"14"
stop-index=
"20"
/>
<projections
start-index=
"7"
stop-index=
"7"
>
<shorthand-projection
start-index=
"7"
stop-index=
"7"
/>
</projections>
<order-by>
<column-item
name=
"order_id"
/>
</order-by>
</select>
<select
sql-case-id=
"select_order_by_with_table_star_without_table_name"
>
<table
name=
"t_order"
alias=
"o"
start-index=
"21"
stop-index=
"27"
/>
<table
name=
"t_order_item"
alias=
"i"
start-index=
"36"
stop-index=
"47"
/>
<projections
start-index=
"7"
stop-index=
"14"
>
<shorthand-projection
start-index=
"7"
stop-index=
"9"
>
<owner
name=
"i"
start-index=
"7"
stop-index=
"7"
/>
</shorthand-projection>
<shorthand-projection
start-index=
"12"
stop-index=
"14"
>
<owner
name=
"o"
start-index=
"12"
stop-index=
"12"
/>
</shorthand-projection>
</projections>
<order-by>
<column-item
name=
"item_id"
/>
</order-by>
</select>
</sql-parser-test-cases>
shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/visitor/dml/select-pagination.xml
0 → 100644
浏览文件 @
e7340f90
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录