Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
3f28158c
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,发现更多精彩内容 >>
提交
3f28158c
编写于
6月 06, 2019
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
for #2441, add RowNumberValueSegment
上级
47367193
变更
35
隐藏空白更改
内联
并排
Showing
35 changed file
with
567 addition
and
180 deletion
+567
-180
sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResult.java
.../merge/dql/pagination/RowNumberDecoratorMergedResult.java
+3
-3
sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResult.java
.../dql/pagination/TopAndRowNumberDecoratorMergedResult.java
+2
-2
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/DQLMergeEngineTest.java
...che/shardingsphere/core/merge/dql/DQLMergeEngineTest.java
+17
-17
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/LimitDecoratorMergedResultTest.java
.../merge/dql/pagination/LimitDecoratorMergedResultTest.java
+6
-6
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
...ge/dql/pagination/RowNumberDecoratorMergedResultTest.java
+8
-6
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java
.../pagination/TopAndRowNumberDecoratorMergedResultTest.java
+9
-11
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/extractor/impl/dml/select/LimitExtractor.java
.../core/parse/extractor/impl/dml/select/LimitExtractor.java
+9
-9
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/extractor/impl/dml/select/item/impl/TopSelectItemExtractor.java
...tor/impl/dml/select/item/impl/TopSelectItemExtractor.java
+6
-6
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/LimitFiller.java
...rdingsphere/core/parse/filler/common/dml/LimitFiller.java
+4
-4
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/SelectItemFiller.java
...sphere/core/parse/filler/common/dml/SelectItemFiller.java
+3
-3
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/sharding/dml/select/ShardingRowNumberPredicateFiller.java
...sharding/dml/select/ShardingRowNumberPredicateFiller.java
+16
-16
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/NumberLiteralPaginationValueSegment.java
...t/dml/pagination/NumberLiteralPaginationValueSegment.java
+35
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationSegment.java
...e/parse/sql/segment/dml/pagination/PaginationSegment.java
+59
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationValueSegment.java
...se/sql/segment/dml/pagination/PaginationValueSegment.java
+39
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/ParameterMarkerPaginationValueSegment.java
...dml/pagination/ParameterMarkerPaginationValueSegment.java
+35
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/LimitValueSegment.java
...e/sql/segment/dml/pagination/limit/LimitValueSegment.java
+33
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/NumberLiteralLimitValueSegment.java
.../dml/pagination/limit/NumberLiteralLimitValueSegment.java
+37
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/ParameterMarkerLimitValueSegment.java
...ml/pagination/limit/ParameterMarkerLimitValueSegment.java
+37
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/NumberLiteralRowNumberValueSegment.java
...pagination/rownum/NumberLiteralRowNumberValueSegment.java
+37
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/ParameterMarkerRowNumberValueSegment.java
...gination/rownum/ParameterMarkerRowNumberValueSegment.java
+37
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/RowNumberValueSegment.java
.../segment/dml/pagination/rownum/RowNumberValueSegment.java
+32
-0
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/top/TopSegment.java
...core/parse/sql/segment/dml/pagination/top/TopSegment.java
+2
-1
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/dml/SelectStatement.java
...gsphere/core/parse/sql/statement/dml/SelectStatement.java
+2
-2
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/filler-rule-definition.xml
...TA-INF/parsing-rule-definition/filler-rule-definition.xml
+1
-1
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/SQLStatementAssert.java
...here/core/parse/integrate/asserts/SQLStatementAssert.java
+4
-4
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/limit/PaginationAssert.java
.../core/parse/integrate/asserts/limit/PaginationAssert.java
+18
-18
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/OffsetTokenGenerator.java
...re/core/rewrite/token/generator/OffsetTokenGenerator.java
+8
-7
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/RowCountTokenGenerator.java
.../core/rewrite/token/generator/RowCountTokenGenerator.java
+8
-7
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OffsetToken.java
...e/shardingsphere/core/rewrite/token/pojo/OffsetToken.java
+1
-1
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RowCountToken.java
...shardingsphere/core/rewrite/token/pojo/RowCountToken.java
+1
-1
sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java
...sphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java
+22
-21
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/Limit.java
...ava/org/apache/shardingsphere/core/route/limit/Limit.java
+15
-13
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/LimitValue.java
...rg/apache/shardingsphere/core/route/limit/LimitValue.java
+2
-2
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/ParsingSQLRouter.java
...ngsphere/core/route/router/sharding/ParsingSQLRouter.java
+2
-2
sharding-core/sharding-core-route/src/test/java/org/apache/shardingsphere/core/route/DatabaseTest.java
...va/org/apache/shardingsphere/core/route/DatabaseTest.java
+17
-17
未找到文件。
sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResult.java
浏览文件 @
3f28158c
...
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.core.route.limit.Limit;
import
java.sql.SQLException
;
/**
* Decorator merged result for row
num
pagination.
* Decorator merged result for row
number
pagination.
*
* @author zhangliang
*/
...
...
@@ -47,7 +47,7 @@ public final class RowNumberDecoratorMergedResult extends DecoratorMergedResult
if
(
null
==
limit
.
getOffset
())
{
end
=
0
;
}
else
{
end
=
limit
.
getOffset
().
get
Limit
ValueSegment
().
isBoundOpened
()
?
limit
.
getOffsetValue
()
-
1
:
limit
.
getOffsetValue
();
end
=
limit
.
getOffset
().
get
Pagination
ValueSegment
().
isBoundOpened
()
?
limit
.
getOffsetValue
()
-
1
:
limit
.
getOffsetValue
();
}
for
(
int
i
=
0
;
i
<
end
;
i
++)
{
if
(!
getMergedResult
().
next
())
{
...
...
@@ -66,7 +66,7 @@ public final class RowNumberDecoratorMergedResult extends DecoratorMergedResult
if
(
limit
.
getRowCountValue
()
<
0
)
{
return
getMergedResult
().
next
();
}
if
(
limit
.
getRowCount
().
get
Limit
ValueSegment
().
isBoundOpened
())
{
if
(
limit
.
getRowCount
().
get
Pagination
ValueSegment
().
isBoundOpened
())
{
return
rowNumber
++
<=
limit
.
getRowCountValue
()
&&
getMergedResult
().
next
();
}
return
rowNumber
++
<
limit
.
getRowCountValue
()
&&
getMergedResult
().
next
();
...
...
sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResult.java
浏览文件 @
3f28158c
...
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.core.route.limit.Limit;
import
java.sql.SQLException
;
/**
* Decorator merged result for top and row
num
pagination.
* Decorator merged result for top and row
number
pagination.
*
* @author zhangliang
*/
...
...
@@ -47,7 +47,7 @@ public final class TopAndRowNumberDecoratorMergedResult extends DecoratorMergedR
if
(
null
==
limit
.
getOffset
())
{
end
=
0
;
}
else
{
end
=
limit
.
getOffset
().
get
Limit
ValueSegment
().
isBoundOpened
()
?
limit
.
getOffsetValue
()
-
1
:
limit
.
getOffsetValue
();
end
=
limit
.
getOffset
().
get
Pagination
ValueSegment
().
isBoundOpened
()
?
limit
.
getOffsetValue
()
-
1
:
limit
.
getOffsetValue
();
}
for
(
int
i
=
0
;
i
<
end
;
i
++)
{
if
(!
getMergedResult
().
next
())
{
...
...
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/DQLMergeEngineTest.java
浏览文件 @
3f28158c
...
...
@@ -33,8 +33,8 @@ import org.apache.shardingsphere.core.merge.dql.pagination.RowNumberDecoratorMer
import
org.apache.shardingsphere.core.merge.dql.pagination.TopAndRowNumberDecoratorMergedResult
;
import
org.apache.shardingsphere.core.merge.fixture.TestQueryResult
;
import
org.apache.shardingsphere.core.parse.sql.context.selectitem.AggregationSelectItem
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
...
...
@@ -91,14 +91,14 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildIteratorStreamMergedResultWithLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
singleQueryResult
);
assertThat
(
mergeEngine
.
merge
(),
instanceOf
(
IteratorStreamMergedResult
.
class
));
}
@Test
public
void
assertBuildIteratorStreamMergedResultWithMySQLLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertThat
(
actual
,
instanceOf
(
LimitDecoratorMergedResult
.
class
));
...
...
@@ -107,7 +107,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildIteratorStreamMergedResultWithOracleLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertThat
(
actual
,
instanceOf
(
RowNumberDecoratorMergedResult
.
class
));
...
...
@@ -116,7 +116,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildIteratorStreamMergedResultWithSQLServerLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertThat
(
actual
,
instanceOf
(
TopAndRowNumberDecoratorMergedResult
.
class
));
...
...
@@ -132,7 +132,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildOrderByStreamMergedResultWithMySQLLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
...
...
@@ -142,7 +142,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildOrderByStreamMergedResultWithOracleLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
...
...
@@ -152,7 +152,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildOrderByStreamMergedResultWithSQLServerLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
...
...
@@ -170,7 +170,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildGroupByStreamMergedResultWithMySQLLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
...
...
@@ -181,7 +181,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildGroupByStreamMergedResultWithOracleLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
...
...
@@ -192,7 +192,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildGroupByStreamMergedResultWithSQLServerLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
...
...
@@ -210,7 +210,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildGroupByMemoryMergedResultWithMySQLLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
...
...
@@ -220,7 +220,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildGroupByMemoryMergedResultWithOracleLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
2
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
...
...
@@ -231,7 +231,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildGroupByMemoryMergedResultWithSQLServerLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
ASC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
...
...
@@ -249,7 +249,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithMySQLLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getItems
().
add
(
new
AggregationSelectItem
(
AggregationType
.
COUNT
,
"(*)"
,
Optional
.<
String
>
absent
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
...
...
@@ -259,7 +259,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getItems
().
add
(
new
AggregationSelectItem
(
AggregationType
.
COUNT
,
"(*)"
,
Optional
.<
String
>
absent
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
...
...
@@ -269,7 +269,7 @@ public final class DQLMergeEngineTest {
@Test
public
void
assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithSQLServerLimit
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
selectStatement
.
getItems
().
add
(
new
AggregationSelectItem
(
AggregationType
.
COUNT
,
"(*)"
,
Optional
.<
String
>
absent
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
...
...
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/LimitDecoratorMergedResultTest.java
浏览文件 @
3f28158c
...
...
@@ -23,8 +23,8 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import
org.apache.shardingsphere.core.merge.MergedResult
;
import
org.apache.shardingsphere.core.merge.dql.DQLMergeEngine
;
import
org.apache.shardingsphere.core.merge.fixture.TestQueryResult
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
...
...
@@ -66,12 +66,12 @@ public final class LimitDecoratorMergedResultTest {
}
SelectStatement
selectStatement
=
new
SelectStatement
();
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
}
@Test
public
void
assertNextForSkipAll
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
Integer
.
MAX_VALUE
,
true
),
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
Integer
.
MAX_VALUE
),
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertFalse
(
actual
.
next
());
...
...
@@ -79,7 +79,7 @@ public final class LimitDecoratorMergedResultTest {
@Test
public
void
assertNextWithoutRowCount
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
,
true
),
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
),
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
...
...
@@ -90,7 +90,7 @@ public final class LimitDecoratorMergedResultTest {
@Test
public
void
assertNextWithRowCount
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
,
false
)),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
),
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
)),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
...
...
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java
浏览文件 @
3f28158c
...
...
@@ -23,8 +23,8 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import
org.apache.shardingsphere.core.merge.MergedResult
;
import
org.apache.shardingsphere.core.merge.dql.DQLMergeEngine
;
import
org.apache.shardingsphere.core.merge.fixture.TestQueryResult
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.rownum.NumberLiteralRowNumber
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
...
...
@@ -69,7 +69,7 @@ public final class RowNumberDecoratorMergedResultTest {
@Test
public
void
assertNextForSkipAll
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimit
ValueSegment
(
0
,
0
,
Integer
.
MAX_VALUE
,
true
),
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumber
ValueSegment
(
0
,
0
,
Integer
.
MAX_VALUE
,
true
),
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertFalse
(
actual
.
next
());
...
...
@@ -77,7 +77,7 @@ public final class RowNumberDecoratorMergedResultTest {
@Test
public
void
assertNextWithoutOffsetWithoutRowCount
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
Limit
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
Pagination
Segment
(
0
,
0
,
null
,
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
...
...
@@ -88,7 +88,8 @@ public final class RowNumberDecoratorMergedResultTest {
@Test
public
void
assertNextForRowCountBoundOpenedFalse
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
0
,
0
,
4
,
false
)),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
0
,
0
,
2
,
true
),
new
NumberLiteralRowNumberValueSegment
(
0
,
0
,
4
,
false
)),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
...
...
@@ -98,7 +99,8 @@ public final class RowNumberDecoratorMergedResultTest {
@Test
public
void
assertNextForRowCountBoundOpenedTrue
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
0
,
0
,
4
,
true
)),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
0
,
0
,
2
,
true
),
new
NumberLiteralRowNumberValueSegment
(
0
,
0
,
4
,
true
)),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
...
...
sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java
浏览文件 @
3f28158c
...
...
@@ -23,8 +23,9 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult;
import
org.apache.shardingsphere.core.merge.MergedResult
;
import
org.apache.shardingsphere.core.merge.dql.DQLMergeEngine
;
import
org.apache.shardingsphere.core.merge.fixture.TestQueryResult
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
...
...
@@ -49,8 +50,6 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
private
List
<
QueryResult
>
queryResults
;
private
SelectStatement
selectStatement
;
private
SQLRouteResult
routeResult
;
@Before
...
...
@@ -66,13 +65,12 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
for
(
ResultSet
each
:
resultSets
)
{
queryResults
.
add
(
new
TestQueryResult
(
each
));
}
selectStatement
=
new
SelectStatement
();
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
=
new
SQLRouteResult
(
new
SelectStatement
());
}
@Test
public
void
assertNextForSkipAll
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimit
ValueSegment
(
0
,
0
,
Integer
.
MAX_VALUE
,
true
),
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumber
ValueSegment
(
0
,
0
,
Integer
.
MAX_VALUE
,
true
),
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertFalse
(
actual
.
next
());
...
...
@@ -80,7 +78,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
public
void
assertNextWithoutOffsetWithRowCount
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
null
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
5
,
false
)),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
null
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
5
)),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
...
...
@@ -91,7 +89,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
public
void
assertNextWithOffsetWithoutRowCount
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimit
ValueSegment
(
0
,
0
,
2
,
true
),
null
),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumber
ValueSegment
(
0
,
0
,
2
,
true
),
null
),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
for
(
int
i
=
0
;
i
<
7
;
i
++)
{
...
...
@@ -102,7 +100,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
public
void
assertNextWithOffsetBoundOpenedFalse
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
,
false
),
new
NumberLiteralLimitValueSegment
(
0
,
0
,
4
,
false
)),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
0
,
0
,
2
,
false
),
new
NumberLiteralLimitValueSegment
(
0
,
0
,
4
)),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
...
...
@@ -112,7 +110,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
public
void
assertNextWithOffsetBoundOpenedTrue
()
throws
SQLException
{
routeResult
.
setLimit
(
new
Limit
(
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
0
,
0
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
0
,
0
,
4
,
false
)),
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
0
,
0
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
0
,
0
,
4
)),
Collections
.
emptyList
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
...
...
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/extractor/impl/dml/select/LimitExtractor.java
浏览文件 @
3f28158c
...
...
@@ -25,10 +25,10 @@ import org.apache.shardingsphere.core.parse.extractor.impl.common.expression.imp
import
org.apache.shardingsphere.core.parse.extractor.util.ExtractorUtils
;
import
org.apache.shardingsphere.core.parse.extractor.util.RuleName
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.LimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.core.util.NumberUtil
;
import
java.util.Map
;
...
...
@@ -45,11 +45,11 @@ public final class LimitExtractor implements OptionalSQLSegmentExtractor {
private
final
ParameterMarkerExpressionExtractor
parameterMarkerExpressionExtractor
=
new
ParameterMarkerExpressionExtractor
();
@Override
public
Optional
<
Limit
Segment
>
extract
(
final
ParserRuleContext
ancestorNode
,
final
Map
<
ParserRuleContext
,
Integer
>
parameterMarkerIndexes
)
{
public
Optional
<
Pagination
Segment
>
extract
(
final
ParserRuleContext
ancestorNode
,
final
Map
<
ParserRuleContext
,
Integer
>
parameterMarkerIndexes
)
{
Optional
<
ParserRuleContext
>
limitNode
=
ExtractorUtils
.
findFirstChildNode
(
ancestorNode
,
RuleName
.
LIMIT_CLAUSE
);
return
limitNode
.
isPresent
()
?
Optional
.
of
(
new
Limit
Segment
(
limitNode
.
get
().
getStart
().
getStartIndex
(),
limitNode
.
get
().
getStop
().
getStopIndex
(),
extractOffset
(
limitNode
.
get
(),
parameterMarkerIndexes
).
orNull
(),
extractRowCount
(
limitNode
.
get
(),
parameterMarkerIndexes
).
orNull
()))
:
Optional
.<
Limit
Segment
>
absent
();
?
Optional
.
of
(
new
Pagination
Segment
(
limitNode
.
get
().
getStart
().
getStartIndex
(),
limitNode
.
get
().
getStop
().
getStopIndex
(),
extractOffset
(
limitNode
.
get
(),
parameterMarkerIndexes
).
orNull
(),
extractRowCount
(
limitNode
.
get
(),
parameterMarkerIndexes
).
orNull
()))
:
Optional
.<
Pagination
Segment
>
absent
();
}
private
Optional
<
LimitValueSegment
>
extractOffset
(
final
ParserRuleContext
limitNode
,
final
Map
<
ParserRuleContext
,
Integer
>
parameterMarkerIndexes
)
{
...
...
@@ -66,11 +66,11 @@ public final class LimitExtractor implements OptionalSQLSegmentExtractor {
Optional
<
ParameterMarkerExpressionSegment
>
parameterMarkerExpression
=
parameterMarkerExpressionExtractor
.
extract
(
limitValueNode
,
parameterMarkerIndexes
);
if
(
parameterMarkerExpression
.
isPresent
())
{
return
new
ParameterMarkerLimitValueSegment
(
limitValueNode
.
getStart
().
getStartIndex
(),
limitValueNode
.
getStop
().
getStopIndex
(),
parameterMarkerExpression
.
get
().
getParameterMarkerIndex
()
,
false
);
limitValueNode
.
getStart
().
getStartIndex
(),
limitValueNode
.
getStop
().
getStopIndex
(),
parameterMarkerExpression
.
get
().
getParameterMarkerIndex
());
}
Optional
<
ParserRuleContext
>
numberLiteralsNode
=
ExtractorUtils
.
findFirstChildNode
(
limitValueNode
,
RuleName
.
NUMBER_LITERALS
);
Preconditions
.
checkState
(
numberLiteralsNode
.
isPresent
());
return
new
NumberLiteralLimitValueSegment
(
limitValueNode
.
getStart
().
getStartIndex
(),
limitValueNode
.
getStop
().
getStopIndex
(),
NumberUtil
.
getExactlyNumber
(
numberLiteralsNode
.
get
().
getText
(),
10
).
intValue
()
,
false
);
limitValueNode
.
getStart
().
getStartIndex
(),
limitValueNode
.
getStop
().
getStopIndex
(),
NumberUtil
.
getExactlyNumber
(
numberLiteralsNode
.
get
().
getText
(),
10
).
intValue
());
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/extractor/impl/dml/select/item/impl/TopSelectItemExtractor.java
浏览文件 @
3f28158c
...
...
@@ -27,10 +27,10 @@ import org.apache.shardingsphere.core.parse.extractor.util.RuleName;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit
.TopSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.LimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.top
.TopSegment
;
import
java.util.Map
;
...
...
@@ -62,11 +62,11 @@ public final class TopSelectItemExtractor implements OptionalSQLSegmentExtractor
private
Optional
<
LimitValueSegment
>
createLimitValueSegment
(
final
ExpressionSegment
topExpr
)
{
if
(
topExpr
instanceof
ParameterMarkerExpressionSegment
)
{
return
Optional
.<
LimitValueSegment
>
of
(
new
ParameterMarkerLimitValueSegment
(
topExpr
.
getStartIndex
(),
topExpr
.
getStopIndex
(),
((
ParameterMarkerExpressionSegment
)
topExpr
).
getParameterMarkerIndex
()
,
false
));
new
ParameterMarkerLimitValueSegment
(
topExpr
.
getStartIndex
(),
topExpr
.
getStopIndex
(),
((
ParameterMarkerExpressionSegment
)
topExpr
).
getParameterMarkerIndex
()));
}
if
(
topExpr
instanceof
LiteralExpressionSegment
&&
((
LiteralExpressionSegment
)
topExpr
).
getLiterals
()
instanceof
Number
)
{
return
Optional
.<
LimitValueSegment
>
of
(
new
NumberLiteralLimitValueSegment
(
topExpr
.
getStartIndex
(),
topExpr
.
getStopIndex
(),
((
Number
)
((
LiteralExpressionSegment
)
topExpr
).
getLiterals
()).
intValue
()
,
false
));
new
NumberLiteralLimitValueSegment
(
topExpr
.
getStartIndex
(),
topExpr
.
getStopIndex
(),
((
Number
)
((
LiteralExpressionSegment
)
topExpr
).
getLiterals
()).
intValue
()));
}
return
Optional
.
absent
();
}
...
...
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/LimitFiller.java
浏览文件 @
3f28158c
...
...
@@ -18,7 +18,7 @@
package
org.apache.shardingsphere.core.parse.filler.common.dml
;
import
org.apache.shardingsphere.core.parse.filler.api.SQLSegmentFiller
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
Segment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
...
...
@@ -27,10 +27,10 @@ import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement;
*
* @author duhongjun
*/
public
final
class
LimitFiller
implements
SQLSegmentFiller
<
Limit
Segment
>
{
public
final
class
LimitFiller
implements
SQLSegmentFiller
<
Pagination
Segment
>
{
@Override
public
void
fill
(
final
Limit
Segment
sqlSegment
,
final
SQLStatement
sqlStatement
)
{
((
SelectStatement
)
sqlStatement
).
set
Limit
(
sqlSegment
);
public
void
fill
(
final
Pagination
Segment
sqlSegment
,
final
SQLStatement
sqlStatement
)
{
((
SelectStatement
)
sqlStatement
).
set
Pagination
(
sqlSegment
);
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/SelectItemFiller.java
浏览文件 @
3f28158c
...
...
@@ -32,8 +32,8 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.item.ColumnSelectIte
import
org.apache.shardingsphere.core.parse.sql.segment.dml.item.ExpressionSelectItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.item.ShorthandSelectItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit
.TopSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.top
.TopSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
...
...
@@ -109,7 +109,7 @@ public final class SelectItemFiller implements SQLSegmentFiller<SelectItemSegmen
}
private
void
fillTopSegment
(
final
TopSegment
topSegment
,
final
SelectStatement
selectStatement
)
{
selectStatement
.
set
Limit
(
new
Limit
Segment
(
topSegment
.
getStartIndex
(),
topSegment
.
getStopIndex
(),
null
,
topSegment
.
getTop
()));
selectStatement
.
set
Pagination
(
new
Pagination
Segment
(
topSegment
.
getStartIndex
(),
topSegment
.
getStopIndex
(),
null
,
topSegment
.
getTop
()));
selectStatement
.
getItems
().
add
(
new
CommonSelectItem
(
"rownum"
,
Optional
.
of
(
topSegment
.
getRowNumberAlias
())));
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/sharding/dml/select/ShardingRowNumberPredicateFiller.java
浏览文件 @
3f28158c
...
...
@@ -23,10 +23,10 @@ import org.apache.shardingsphere.core.parse.sql.context.selectitem.SelectItem;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.ParameterMarkerLimit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.rownum.NumberLiteralRowNumber
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.rownum.ParameterMarkerRowNumber
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.rownum.RowNumber
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.AndPredicate
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.OrPredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment
;
...
...
@@ -98,34 +98,34 @@ public final class ShardingRowNumberPredicateFiller implements SQLSegmentFiller<
}
private
void
fillLimit
(
final
SelectStatement
selectStatement
,
final
Collection
<
PredicateSegment
>
rowNumberPredicates
)
{
Limit
ValueSegment
rowCount
=
null
;
Limit
ValueSegment
offset
=
null
;
RowNumber
ValueSegment
rowCount
=
null
;
RowNumber
ValueSegment
offset
=
null
;
for
(
PredicateSegment
each
:
rowNumberPredicates
)
{
ExpressionSegment
expression
=
((
PredicateCompareRightValue
)
each
.
getRightValue
()).
getExpression
();
switch
(((
PredicateCompareRightValue
)
each
.
getRightValue
()).
getOperator
())
{
case
">"
:
offset
=
create
Limit
ValueSegment
(
expression
,
false
);
offset
=
create
RowNumber
ValueSegment
(
expression
,
false
);
break
;
case
">="
:
offset
=
create
Limit
ValueSegment
(
expression
,
true
);
offset
=
create
RowNumber
ValueSegment
(
expression
,
true
);
break
;
case
"<"
:
rowCount
=
create
Limit
ValueSegment
(
expression
,
false
);
rowCount
=
create
RowNumber
ValueSegment
(
expression
,
false
);
break
;
case
"<="
:
rowCount
=
create
Limit
ValueSegment
(
expression
,
true
);
rowCount
=
create
RowNumber
ValueSegment
(
expression
,
true
);
break
;
default
:
break
;
}
}
selectStatement
.
set
Limit
(
new
Limit
Segment
(-
1
,
-
1
,
offset
,
rowCount
));
selectStatement
.
set
Pagination
(
new
Pagination
Segment
(-
1
,
-
1
,
offset
,
rowCount
));
}
private
LimitValueSegment
createLimit
ValueSegment
(
final
ExpressionSegment
expression
,
final
boolean
boundOpened
)
{
if
(
expression
instanceof
LiteralExpressionSegment
)
{
return
new
NumberLiteralLimitValueSegment
(
expression
.
getStartIndex
(),
expression
.
getStopIndex
(),
(
Integer
)
((
LiteralExpressionSegment
)
expression
).
getLiterals
(),
boundOpened
);
}
return
new
ParameterMarkerLimitValueSegment
(
expression
.
getStartIndex
(),
expression
.
getStopIndex
(),
((
ParameterMarkerExpressionSegment
)
expression
).
getParameterMarkerIndex
(),
boundOpened
);
private
RowNumberValueSegment
createRowNumber
ValueSegment
(
final
ExpressionSegment
expression
,
final
boolean
boundOpened
)
{
return
expression
instanceof
LiteralExpressionSegment
?
new
NumberLiteralRowNumberValueSegment
(
expression
.
getStartIndex
(),
expression
.
getStopIndex
(),
(
int
)
((
LiteralExpressionSegment
)
expression
).
getLiterals
(),
boundOpened
)
:
new
ParameterMarkerRowNumberValueSegment
(
expression
.
getStartIndex
(),
expression
.
getStopIndex
(),
((
ParameterMarkerExpressionSegment
)
expression
).
getParameterMarkerIndex
(),
boundOpened
);
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/NumberLiteralPaginationValueSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination
;
import
org.apache.shardingsphere.core.parse.sql.segment.SQLSegment
;
/**
* Pagination value segment for number literal.
*
* @author zhangliang
*/
public
interface
NumberLiteralPaginationValueSegment
extends
SQLSegment
{
/**
* Get value.
*
* @return value
*/
int
getValue
();
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination
;
import
com.google.common.base.Optional
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.sql.segment.SQLSegment
;
/**
* Pagination segment.
*
* @author duhongjun
*/
@RequiredArgsConstructor
@Getter
public
final
class
PaginationSegment
implements
SQLSegment
{
private
final
int
startIndex
;
private
final
int
stopIndex
;
private
final
PaginationValueSegment
offset
;
private
final
PaginationValueSegment
rowCount
;
/**
* Get offset.
*
* @return offset
*/
public
Optional
<
PaginationValueSegment
>
getOffset
()
{
return
Optional
.
fromNullable
(
offset
);
}
/**
* Get row count.
*
* @return row count
*/
public
Optional
<
PaginationValueSegment
>
getRowCount
()
{
return
Optional
.
fromNullable
(
rowCount
);
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationValueSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.sql.segment.SQLSegment
;
/**
* Pagination value segment.
*
* @author zhangliang
* @author panjuan
*/
@RequiredArgsConstructor
@Getter
public
abstract
class
PaginationValueSegment
implements
SQLSegment
{
private
final
int
startIndex
;
private
final
int
stopIndex
;
private
final
boolean
boundOpened
;
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/ParameterMarkerPaginationValueSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination
;
import
org.apache.shardingsphere.core.parse.sql.segment.SQLSegment
;
/**
* Pagination value segment for parameter marker.
*
* @author zhangliang
*/
public
interface
ParameterMarkerPaginationValueSegment
extends
SQLSegment
{
/**
* Get parameter index.
*
* @return parameter index
*/
int
getParameterIndex
();
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/LimitValueSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination.limit
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment
;
/**
* Limit value segment.
*
* @author zhangliang
* @author panjuan
*/
public
abstract
class
LimitValueSegment
extends
PaginationValueSegment
{
public
LimitValueSegment
(
final
int
startIndex
,
final
int
stopIndex
)
{
super
(
startIndex
,
stopIndex
,
false
);
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/NumberLiteralLimitValueSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination.limit
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment
;
/**
* Limit value segment for number literal.
*
* @author zhangliang
*/
@Getter
public
final
class
NumberLiteralLimitValueSegment
extends
LimitValueSegment
implements
NumberLiteralPaginationValueSegment
{
private
final
int
value
;
public
NumberLiteralLimitValueSegment
(
final
int
startIndex
,
final
int
stopIndex
,
final
int
value
)
{
super
(
startIndex
,
stopIndex
);
this
.
value
=
value
;
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/ParameterMarkerLimitValueSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination.limit
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.ParameterMarkerPaginationValueSegment
;
/**
* Limit value segment for parameter marker.
*
* @author zhangliang
*/
@Getter
public
final
class
ParameterMarkerLimitValueSegment
extends
LimitValueSegment
implements
ParameterMarkerPaginationValueSegment
{
private
final
int
parameterIndex
;
public
ParameterMarkerLimitValueSegment
(
final
int
startIndex
,
final
int
stopIndex
,
final
int
parameterIndex
)
{
super
(
startIndex
,
stopIndex
);
this
.
parameterIndex
=
parameterIndex
;
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/NumberLiteralRowNumberValueSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination.rownum
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment
;
/**
* Row number value segment for number literal.
*
* @author zhangliang
*/
@Getter
public
final
class
NumberLiteralRowNumberValueSegment
extends
RowNumberValueSegment
implements
NumberLiteralPaginationValueSegment
{
private
final
int
value
;
public
NumberLiteralRowNumberValueSegment
(
final
int
startIndex
,
final
int
stopIndex
,
final
int
value
,
final
boolean
boundOpened
)
{
super
(
startIndex
,
stopIndex
,
boundOpened
);
this
.
value
=
value
;
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/ParameterMarkerRowNumberValueSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination.rownum
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.ParameterMarkerPaginationValueSegment
;
/**
* Row number value segment for parameter marker.
*
* @author zhangliang
*/
@Getter
public
final
class
ParameterMarkerRowNumberValueSegment
extends
RowNumberValueSegment
implements
ParameterMarkerPaginationValueSegment
{
private
final
int
parameterIndex
;
public
ParameterMarkerRowNumberValueSegment
(
final
int
startIndex
,
final
int
stopIndex
,
final
int
parameterIndex
,
final
boolean
boundOpened
)
{
super
(
startIndex
,
stopIndex
,
boundOpened
);
this
.
parameterIndex
=
parameterIndex
;
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/RowNumberValueSegment.java
0 → 100644
浏览文件 @
3f28158c
/*
* 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.core.parse.sql.segment.dml.pagination.rownum
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment
;
/**
* Row number value segment.
*
* @author zhangliang
*/
public
abstract
class
RowNumberValueSegment
extends
PaginationValueSegment
{
public
RowNumberValueSegment
(
final
int
startIndex
,
final
int
stopIndex
,
final
boolean
boundOpened
)
{
super
(
startIndex
,
stopIndex
,
boundOpened
);
}
}
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/
limit
/TopSegment.java
→
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/
pagination/top
/TopSegment.java
浏览文件 @
3f28158c
...
...
@@ -15,11 +15,12 @@
* limitations under the License.
*/
package
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit
;
package
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.top
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.LimitValueSegment
;
/**
* Top segment.
...
...
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/dml/SelectStatement.java
浏览文件 @
3f28158c
...
...
@@ -29,12 +29,12 @@ import org.apache.shardingsphere.core.parse.sql.context.selectitem.DistinctSelec
import
org.apache.shardingsphere.core.parse.sql.context.selectitem.SelectItem
;
import
org.apache.shardingsphere.core.parse.sql.context.selectitem.StarSelectItem
;
import
org.apache.shardingsphere.core.parse.sql.context.table.Table
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ColumnOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ExpressionOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.OrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.TextOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment
;
import
org.apache.shardingsphere.core.parse.util.SQLUtil
;
import
java.util.Collection
;
...
...
@@ -71,7 +71,7 @@ public final class SelectStatement extends DQLStatement {
private
int
groupByLastIndex
;
private
LimitSegment
limit
;
private
PaginationSegment
pagination
;
private
SelectStatement
parentStatement
;
...
...
sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/filler-rule-definition.xml
浏览文件 @
3f28158c
...
...
@@ -29,7 +29,7 @@
<filler-rule
sql-segment-class=
"org.apache.shardingsphere.core.parse.sql.segment.dml.WhereSegment"
filler-class=
"org.apache.shardingsphere.core.parse.filler.common.dml.WhereFiller"
/>
<filler-rule
sql-segment-class=
"org.apache.shardingsphere.core.parse.sql.segment.dml.order.GroupBySegment"
filler-class=
"org.apache.shardingsphere.core.parse.filler.common.dml.GroupByFiller"
/>
<filler-rule
sql-segment-class=
"org.apache.shardingsphere.core.parse.sql.segment.dml.order.OrderBySegment"
filler-class=
"org.apache.shardingsphere.core.parse.filler.common.dml.OrderByFiller"
/>
<filler-rule
sql-segment-class=
"org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
Segment"
filler-class=
"org.apache.shardingsphere.core.parse.filler.common.dml.LimitFiller"
/>
<filler-rule
sql-segment-class=
"org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
Segment"
filler-class=
"org.apache.shardingsphere.core.parse.filler.common.dml.LimitFiller"
/>
<filler-rule
sql-segment-class=
"org.apache.shardingsphere.core.parse.sql.segment.common.SchemaSegment"
filler-class=
"org.apache.shardingsphere.core.parse.filler.common.dal.SchemaFiller"
/>
</filler-rule-definition>
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/SQLStatementAssert.java
浏览文件 @
3f28158c
...
...
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.core.parse.integrate.asserts.condition.Conditio
import
org.apache.shardingsphere.core.parse.integrate.asserts.groupby.GroupByAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.index.IndexAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.item.ItemAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.limit.
Limit
Assert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.limit.
Pagination
Assert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.meta.TableMetaDataAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.orderby.OrderByAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.table.AlterTableAssert
;
...
...
@@ -61,7 +61,7 @@ public final class SQLStatementAssert {
private
final
OrderByAssert
orderByAssert
;
private
final
LimitAssert
limit
Assert
;
private
final
PaginationAssert
pagination
Assert
;
private
final
TableMetaDataAssert
metaAssert
;
...
...
@@ -84,7 +84,7 @@ public final class SQLStatementAssert {
itemAssert
=
new
ItemAssert
(
assertMessage
);
groupByAssert
=
new
GroupByAssert
(
assertMessage
);
orderByAssert
=
new
OrderByAssert
(
assertMessage
);
limitAssert
=
new
Limit
Assert
(
sqlCaseType
,
assertMessage
);
paginationAssert
=
new
Pagination
Assert
(
sqlCaseType
,
assertMessage
);
metaAssert
=
new
TableMetaDataAssert
(
assertMessage
);
alterTableAssert
=
new
AlterTableAssert
(
assertMessage
);
this
.
databaseType
=
databaseType
;
...
...
@@ -118,7 +118,7 @@ public final class SQLStatementAssert {
itemAssert
.
assertItems
(
actual
.
getItems
(),
expected
.
getSelectItems
());
groupByAssert
.
assertGroupByItems
(
actual
.
getGroupByItems
(),
expected
.
getGroupByColumns
());
orderByAssert
.
assertOrderByItems
(
actual
.
getOrderByItems
(),
expected
.
getOrderByColumns
());
limitAssert
.
assertLimit
(
actual
.
getLimit
(),
expected
.
getLimit
());
paginationAssert
.
assertPagination
(
actual
.
getPagination
(),
expected
.
getLimit
());
}
private
void
assertCreateTableStatement
(
final
CreateTableStatement
actual
)
{
...
...
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/limit/
Limit
Assert.java
→
sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/limit/
Pagination
Assert.java
浏览文件 @
3f28158c
...
...
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.core.parse.integrate.asserts.limit;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.SQLStatementAssertMessage
;
import
org.apache.shardingsphere.core.parse.integrate.jaxb.limit.ExpectedLimit
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimitValue
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.ParameterMarkerLimit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.NumberLiteralPaginationValue
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.ParameterMarkerPagination
ValueSegment
;
import
org.apache.shardingsphere.test.sql.SQLCaseType
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
...
...
@@ -30,45 +30,45 @@ import static org.junit.Assert.assertNull;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
*
Limit
assert.
*
Pagination
assert.
*
* @author zhangliang
*/
@RequiredArgsConstructor
public
final
class
Limit
Assert
{
public
final
class
Pagination
Assert
{
private
final
SQLCaseType
sqlCaseType
;
private
final
SQLStatementAssertMessage
assertMessage
;
/**
* Assert
limit
.
* Assert
pagination
.
*
* @param actual actual
limit
* @param expected expected
limit
* @param actual actual
pagination
* @param expected expected
pagination
*/
public
void
assert
Limit
(
final
Limit
Segment
actual
,
final
ExpectedLimit
expected
)
{
public
void
assert
Pagination
(
final
Pagination
Segment
actual
,
final
ExpectedLimit
expected
)
{
if
(
null
==
actual
)
{
assertNull
(
assertMessage
.
getFullAssertMessage
(
"
Limit
should not exist: "
),
expected
);
assertNull
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
should not exist: "
),
expected
);
return
;
}
if
(
SQLCaseType
.
Placeholder
==
sqlCaseType
)
{
if
(
actual
.
getOffset
().
isPresent
())
{
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Limit
offset index assertion error: "
),
((
ParameterMarker
Limit
ValueSegment
)
actual
.
getOffset
().
get
()).
getParameterIndex
(),
is
(
expected
.
getOffsetParameterIndex
()));
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
offset index assertion error: "
),
((
ParameterMarker
Pagination
ValueSegment
)
actual
.
getOffset
().
get
()).
getParameterIndex
(),
is
(
expected
.
getOffsetParameterIndex
()));
}
if
(
actual
.
getRowCount
().
isPresent
())
{
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Limit
row count index assertion error: "
),
((
ParameterMarker
Limit
ValueSegment
)
actual
.
getRowCount
().
get
()).
getParameterIndex
(),
is
(
expected
.
getRowCountParameterIndex
()));
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
row count index assertion error: "
),
((
ParameterMarker
Pagination
ValueSegment
)
actual
.
getRowCount
().
get
()).
getParameterIndex
(),
is
(
expected
.
getRowCountParameterIndex
()));
}
}
else
{
if
(
actual
.
getOffset
().
isPresent
())
{
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Limit
offset value assertion error: "
),
((
NumberLiteral
Limit
ValueSegment
)
actual
.
getOffset
().
get
()).
getValue
(),
is
(
expected
.
getOffset
()));
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
offset value assertion error: "
),
((
NumberLiteral
Pagination
ValueSegment
)
actual
.
getOffset
().
get
()).
getValue
(),
is
(
expected
.
getOffset
()));
}
if
(
actual
.
getRowCount
().
isPresent
())
{
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Limit
row count value assertion error: "
),
((
NumberLiteral
Limit
ValueSegment
)
actual
.
getRowCount
().
get
()).
getValue
(),
is
(
expected
.
getRowCount
()));
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
row count value assertion error: "
),
((
NumberLiteral
Pagination
ValueSegment
)
actual
.
getRowCount
().
get
()).
getValue
(),
is
(
expected
.
getRowCount
()));
}
}
}
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/OffsetTokenGenerator.java
浏览文件 @
3f28158c
...
...
@@ -18,8 +18,8 @@
package
org.apache.shardingsphere.core.rewrite.token.generator
;
import
com.google.common.base.Optional
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.NumberLiteralPagination
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.OffsetToken
;
...
...
@@ -37,17 +37,18 @@ public final class OffsetTokenGenerator implements OptionalSQLTokenGenerator<Sha
if
(!(
sqlStatement
instanceof
SelectStatement
))
{
return
Optional
.
absent
();
}
Optional
<
Limit
ValueSegment
>
offsetSegment
=
getLiteralOffsetSegment
((
SelectStatement
)
sqlStatement
);
Optional
<
Pagination
ValueSegment
>
offsetSegment
=
getLiteralOffsetSegment
((
SelectStatement
)
sqlStatement
);
return
offsetSegment
.
isPresent
()
?
Optional
.
of
(
new
OffsetToken
(
offsetSegment
.
get
().
getStartIndex
(),
offsetSegment
.
get
().
getStopIndex
(),
((
NumberLiteral
Limit
ValueSegment
)
offsetSegment
.
get
()).
getValue
()))
?
Optional
.
of
(
new
OffsetToken
(
offsetSegment
.
get
().
getStartIndex
(),
offsetSegment
.
get
().
getStopIndex
(),
((
NumberLiteral
Pagination
ValueSegment
)
offsetSegment
.
get
()).
getValue
()))
:
Optional
.<
OffsetToken
>
absent
();
}
private
Optional
<
Limit
ValueSegment
>
getLiteralOffsetSegment
(
final
SelectStatement
selectStatement
)
{
return
isLiteralOffset
(
selectStatement
)
?
selectStatement
.
get
Limit
().
getOffset
()
:
Optional
.<
Limit
ValueSegment
>
absent
();
private
Optional
<
Pagination
ValueSegment
>
getLiteralOffsetSegment
(
final
SelectStatement
selectStatement
)
{
return
isLiteralOffset
(
selectStatement
)
?
selectStatement
.
get
Pagination
().
getOffset
()
:
Optional
.<
Pagination
ValueSegment
>
absent
();
}
private
boolean
isLiteralOffset
(
final
SelectStatement
selectStatement
)
{
return
null
!=
selectStatement
.
getLimit
()
&&
selectStatement
.
getLimit
().
getOffset
().
isPresent
()
&&
selectStatement
.
getLimit
().
getOffset
().
get
()
instanceof
NumberLiteralLimitValueSegment
;
return
null
!=
selectStatement
.
getPagination
()
&&
selectStatement
.
getPagination
().
getOffset
().
isPresent
()
&&
selectStatement
.
getPagination
().
getOffset
().
get
()
instanceof
NumberLiteralPaginationValueSegment
;
}
}
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/RowCountTokenGenerator.java
浏览文件 @
3f28158c
...
...
@@ -18,8 +18,8 @@
package
org.apache.shardingsphere.core.rewrite.token.generator
;
import
com.google.common.base.Optional
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.NumberLiteralPagination
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.RowCountToken
;
...
...
@@ -37,17 +37,18 @@ public final class RowCountTokenGenerator implements OptionalSQLTokenGenerator<S
if
(!(
sqlStatement
instanceof
SelectStatement
))
{
return
Optional
.
absent
();
}
Optional
<
Limit
ValueSegment
>
rowCountSegment
=
getLiteralRowCountSegment
((
SelectStatement
)
sqlStatement
);
Optional
<
Pagination
ValueSegment
>
rowCountSegment
=
getLiteralRowCountSegment
((
SelectStatement
)
sqlStatement
);
return
rowCountSegment
.
isPresent
()
?
Optional
.
of
(
new
RowCountToken
(
rowCountSegment
.
get
().
getStartIndex
(),
rowCountSegment
.
get
().
getStopIndex
(),
((
NumberLiteral
Limit
ValueSegment
)
rowCountSegment
.
get
()).
getValue
()))
?
Optional
.
of
(
new
RowCountToken
(
rowCountSegment
.
get
().
getStartIndex
(),
rowCountSegment
.
get
().
getStopIndex
(),
((
NumberLiteral
Pagination
ValueSegment
)
rowCountSegment
.
get
()).
getValue
()))
:
Optional
.<
RowCountToken
>
absent
();
}
private
Optional
<
Limit
ValueSegment
>
getLiteralRowCountSegment
(
final
SelectStatement
selectStatement
)
{
return
isLiteralRowCount
(
selectStatement
)
?
selectStatement
.
get
Limit
().
getRowCount
()
:
Optional
.<
Limit
ValueSegment
>
absent
();
private
Optional
<
Pagination
ValueSegment
>
getLiteralRowCountSegment
(
final
SelectStatement
selectStatement
)
{
return
isLiteralRowCount
(
selectStatement
)
?
selectStatement
.
get
Pagination
().
getRowCount
()
:
Optional
.<
Pagination
ValueSegment
>
absent
();
}
private
boolean
isLiteralRowCount
(
final
SelectStatement
selectStatement
)
{
return
null
!=
selectStatement
.
getLimit
()
&&
selectStatement
.
getLimit
().
getRowCount
().
isPresent
()
&&
selectStatement
.
getLimit
().
getRowCount
().
get
()
instanceof
NumberLiteralLimitValueSegment
;
return
null
!=
selectStatement
.
getPagination
()
&&
selectStatement
.
getPagination
().
getRowCount
().
isPresent
()
&&
selectStatement
.
getPagination
().
getRowCount
().
get
()
instanceof
NumberLiteralPaginationValueSegment
;
}
}
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OffsetToken.java
浏览文件 @
3f28158c
...
...
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.Getter
;
/**
* Offset token for
limit
.
* Offset token for
pagination
.
*
* @author zhangliang
* @author panjuan
...
...
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RowCountToken.java
浏览文件 @
3f28158c
...
...
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.Getter
;
/**
* Row count token for
limit
.
* Row count token for
pagination
.
*
* @author zhangliang
* @author panjuan
...
...
sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java
浏览文件 @
3f28158c
...
...
@@ -46,9 +46,10 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegme
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.item.AggregationDistinctSelectItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ColumnOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.dal.DALStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.DeleteStatement
;
...
...
@@ -346,8 +347,8 @@ public final class ShardingSQLRewriterTest {
@Test
public
void
assertRewriteForLimit
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
));
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
17
,
23
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
...
@@ -358,9 +359,9 @@ public final class ShardingSQLRewriterTest {
}
@Test
public
void
assertRewriteForRowNum
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralLimit
ValueSegment
(
98
,
98
,
4
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
public
void
assertRewriteForRowNum
ber
()
{
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralRowNumber
ValueSegment
(
98
,
98
,
4
,
false
));
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
68
,
74
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
...
@@ -373,8 +374,8 @@ public final class ShardingSQLRewriterTest {
@Test
public
void
assertRewriteForTopAndRowNumber
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
));
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
85
,
91
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
...
@@ -387,8 +388,8 @@ public final class ShardingSQLRewriterTest {
@Test
public
void
assertRewriteForLimitForMemoryGroupBy
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
));
selectStatement
.
set
Pagination
(
limitSegment
);
ColumnSegment
columnSegment
=
new
ColumnSegment
(
0
,
0
,
"id"
);
columnSegment
.
setOwner
(
new
TableSegment
(
0
,
0
,
"x"
));
selectStatement
.
getOrderByItems
().
add
(
new
ColumnOrderByItemSegment
(
0
,
0
,
columnSegment
,
OrderDirection
.
ASC
,
OrderDirection
.
ASC
));
...
...
@@ -404,8 +405,8 @@ public final class ShardingSQLRewriterTest {
@Test
public
void
assertRewriteForRowNumForMemoryGroupBy
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralLimit
ValueSegment
(
98
,
98
,
4
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralRowNumber
ValueSegment
(
98
,
98
,
4
,
false
));
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
68
,
74
,
"table_x"
));
ColumnSegment
columnSegment
=
new
ColumnSegment
(
0
,
0
,
"id"
);
columnSegment
.
setOwner
(
new
TableSegment
(
0
,
0
,
"x"
));
...
...
@@ -422,8 +423,8 @@ public final class ShardingSQLRewriterTest {
@Test
public
void
assertRewriteForTopAndRowNumberForMemoryGroupBy
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
123
,
123
,
2
,
false
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
));
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
85
,
91
,
"table_x"
));
ColumnSegment
columnSegment
=
new
ColumnSegment
(
0
,
0
,
"id"
);
columnSegment
.
setOwner
(
new
TableSegment
(
0
,
0
,
"x"
));
...
...
@@ -440,8 +441,8 @@ public final class ShardingSQLRewriterTest {
@Test
public
void
assertRewriteForLimitForNotRewriteLimit
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
));
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
17
,
23
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
...
@@ -455,8 +456,8 @@ public final class ShardingSQLRewriterTest {
@Test
public
void
assertRewriteForRowNumForNotRewriteLimit
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralLimit
ValueSegment
(
98
,
98
,
4
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralRowNumber
ValueSegment
(
98
,
98
,
4
,
false
));
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
68
,
74
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
...
@@ -471,8 +472,8 @@ public final class ShardingSQLRewriterTest {
@Test
public
void
assertRewriteForTopAndRowNumberForNotRewriteLimit
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
));
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
85
,
91
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
...
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/Limit.java
浏览文件 @
3f28158c
...
...
@@ -18,10 +18,11 @@
package
org.apache.shardingsphere.core.route.limit
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.ParameterMarkerPaginationValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.ParameterMarkerLimitValueSegment
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -41,15 +42,16 @@ public final class Limit {
private
final
LimitValue
rowCount
;
public
Limit
(
final
Limit
Segment
limitSegment
,
final
List
<
Object
>
parameters
)
{
public
Limit
(
final
Pagination
Segment
limitSegment
,
final
List
<
Object
>
parameters
)
{
offset
=
limitSegment
.
getOffset
().
isPresent
()
?
createLimitValue
(
limitSegment
.
getOffset
().
get
(),
parameters
)
:
null
;
rowCount
=
limitSegment
.
getRowCount
().
isPresent
()
?
createLimitValue
(
limitSegment
.
getRowCount
().
get
(),
parameters
)
:
null
;
}
private
LimitValue
createLimitValue
(
final
LimitValueSegment
limitValueSegment
,
final
List
<
Object
>
parameters
)
{
int
segmentValue
=
limitValueSegment
instanceof
ParameterMarkerLimitValueSegment
?
(
int
)
parameters
.
get
(((
ParameterMarkerLimitValueSegment
)
limitValueSegment
).
getParameterIndex
())
:
((
NumberLiteralLimitValueSegment
)
limitValueSegment
).
getValue
();
return
new
LimitValue
(
limitValueSegment
,
segmentValue
);
private
LimitValue
createLimitValue
(
final
PaginationValueSegment
paginationValueSegment
,
final
List
<
Object
>
parameters
)
{
int
segmentValue
=
paginationValueSegment
instanceof
ParameterMarkerPaginationValueSegment
?
(
int
)
parameters
.
get
(((
ParameterMarkerPaginationValueSegment
)
paginationValueSegment
).
getParameterIndex
())
:
((
NumberLiteralPaginationValueSegment
)
paginationValueSegment
).
getValue
();
return
new
LimitValue
(
paginationValueSegment
,
segmentValue
);
}
/**
...
...
@@ -79,11 +81,11 @@ public final class Limit {
*/
public
Map
<
Integer
,
Object
>
getRevisedParameters
(
final
boolean
isFetchAll
,
final
String
databaseType
)
{
Map
<
Integer
,
Object
>
result
=
new
HashMap
<>(
2
,
1
);
if
(
null
!=
offset
&&
offset
.
get
Limit
ValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
result
.
put
(((
ParameterMarkerLimitValueSegment
)
offset
.
get
Limit
ValueSegment
()).
getParameterIndex
(),
0
);
if
(
null
!=
offset
&&
offset
.
get
Pagination
ValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
result
.
put
(((
ParameterMarkerLimitValueSegment
)
offset
.
get
Pagination
ValueSegment
()).
getParameterIndex
(),
0
);
}
if
(
null
!=
rowCount
&&
rowCount
.
get
Limit
ValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
result
.
put
(((
ParameterMarkerLimitValueSegment
)
rowCount
.
get
Limit
ValueSegment
()).
getParameterIndex
(),
getRewriteRowCount
(
isFetchAll
,
databaseType
));
if
(
null
!=
rowCount
&&
rowCount
.
get
Pagination
ValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
result
.
put
(((
ParameterMarkerLimitValueSegment
)
rowCount
.
get
Pagination
ValueSegment
()).
getParameterIndex
(),
getRewriteRowCount
(
isFetchAll
,
databaseType
));
}
return
result
;
}
...
...
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/LimitValue.java
浏览文件 @
3f28158c
...
...
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.core.route.limit;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.Limit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
ValueSegment
;
/**
* Limit value.
...
...
@@ -30,7 +30,7 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegm
@Getter
public
final
class
LimitValue
{
private
final
LimitValueSegment
limit
ValueSegment
;
private
final
PaginationValueSegment
pagination
ValueSegment
;
private
final
int
value
;
}
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/ParsingSQLRouter.java
浏览文件 @
3f28158c
...
...
@@ -103,8 +103,8 @@ public final class ParsingSQLRouter implements ShardingRouter {
mergeShardingValues
(
optimizeResult
.
getShardingConditions
());
}
RoutingResult
routingResult
=
RoutingEngineFactory
.
newInstance
(
shardingRule
,
shardingMetaData
.
getDataSource
(),
sqlStatement
,
optimizeResult
).
route
();
if
(
sqlStatement
instanceof
SelectStatement
&&
null
!=
((
SelectStatement
)
sqlStatement
).
get
Limit
()
&&
!
routingResult
.
isSingleRouting
())
{
result
.
setLimit
(
new
Limit
(((
SelectStatement
)
sqlStatement
).
get
Limit
(),
parameters
));
if
(
sqlStatement
instanceof
SelectStatement
&&
null
!=
((
SelectStatement
)
sqlStatement
).
get
Pagination
()
&&
!
routingResult
.
isSingleRouting
())
{
result
.
setLimit
(
new
Limit
(((
SelectStatement
)
sqlStatement
).
get
Pagination
(),
parameters
));
}
if
(
needMerge
)
{
Preconditions
.
checkState
(
1
==
routingResult
.
getRoutingUnits
().
size
(),
"Must have one sharding with subquery."
);
...
...
sharding-core/sharding-core-route/src/test/java/org/apache/shardingsphere/core/route/DatabaseTest.java
浏览文件 @
3f28158c
...
...
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.core.constant.DatabaseType;
import
org.apache.shardingsphere.core.metadata.ShardingMetaData
;
import
org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData
;
import
org.apache.shardingsphere.core.parse.cache.ParsingResultCache
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.fixture.HintShardingAlgorithmFixture
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
...
...
@@ -89,17 +89,17 @@ public final class DatabaseTest {
String
originSQL
=
"select user_id from tbl_pagination limit 0,5"
;
SQLRouteResult
actual
=
new
StatementRoutingEngine
(
shardingRule
,
mock
(
ShardingMetaData
.
class
),
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
originSQL
);
SelectStatement
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
assertTrue
(
selectStatement
.
get
Limit
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getOffset
().
get
()).
getValue
(),
is
(
0
));
assertTrue
(
selectStatement
.
get
Limit
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getRowCount
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Pagination
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getOffset
().
get
()).
getValue
(),
is
(
0
));
assertTrue
(
selectStatement
.
get
Pagination
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getRowCount
().
get
()).
getValue
(),
is
(
5
));
originSQL
=
"select user_id from tbl_pagination limit 5,5"
;
actual
=
new
StatementRoutingEngine
(
shardingRule
,
mock
(
ShardingMetaData
.
class
),
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
originSQL
);
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
assertTrue
(
selectStatement
.
get
Limit
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Limit
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getRowCount
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Pagination
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Pagination
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getRowCount
().
get
()).
getValue
(),
is
(
5
));
}
@Test
...
...
@@ -119,18 +119,18 @@ public final class DatabaseTest {
when
(
shardingMetaData
.
getTable
()).
thenReturn
(
mock
(
ShardingTableMetaData
.
class
));
SQLRouteResult
actual
=
new
PreparedStatementRoutingEngine
(
originSQL
,
rule
,
shardingMetaData
,
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
Lists
.<
Object
>
newArrayList
(
13
,
173
));
SelectStatement
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
assertTrue
(
selectStatement
.
get
Limit
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Limit
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getRowCount
().
get
()).
getValue
(),
is
(
10
));
assertTrue
(
selectStatement
.
get
Pagination
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Pagination
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getRowCount
().
get
()).
getValue
(),
is
(
10
));
assertThat
(
actual
.
getRoutingResult
().
getRoutingUnits
().
size
(),
is
(
1
));
originSQL
=
"select city_id from t_user where city_id in (?,?) limit 5,10"
;
actual
=
new
PreparedStatementRoutingEngine
(
originSQL
,
rule
,
shardingMetaData
,
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
Lists
.<
Object
>
newArrayList
(
89
,
84
));
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
assertTrue
(
selectStatement
.
get
Limit
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Limit
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getRowCount
().
get
()).
getValue
(),
is
(
10
));
assertTrue
(
selectStatement
.
get
Pagination
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Pagination
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getRowCount
().
get
()).
getValue
(),
is
(
10
));
assertThat
(
actual
.
getRoutingResult
().
getRoutingUnits
().
size
(),
is
(
2
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录