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;
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.core.route.limit.Limit;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
/**
/**
* Decorator merged result for row
num
pagination.
* Decorator merged result for row
number
pagination.
*
*
* @author zhangliang
* @author zhangliang
*/
*/
...
@@ -47,7 +47,7 @@ public final class RowNumberDecoratorMergedResult extends DecoratorMergedResult
...
@@ -47,7 +47,7 @@ public final class RowNumberDecoratorMergedResult extends DecoratorMergedResult
if
(
null
==
limit
.
getOffset
())
{
if
(
null
==
limit
.
getOffset
())
{
end
=
0
;
end
=
0
;
}
else
{
}
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
++)
{
for
(
int
i
=
0
;
i
<
end
;
i
++)
{
if
(!
getMergedResult
().
next
())
{
if
(!
getMergedResult
().
next
())
{
...
@@ -66,7 +66,7 @@ public final class RowNumberDecoratorMergedResult extends DecoratorMergedResult
...
@@ -66,7 +66,7 @@ public final class RowNumberDecoratorMergedResult extends DecoratorMergedResult
if
(
limit
.
getRowCountValue
()
<
0
)
{
if
(
limit
.
getRowCountValue
()
<
0
)
{
return
getMergedResult
().
next
();
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
();
}
}
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;
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.core.route.limit.Limit;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
/**
/**
* Decorator merged result for top and row
num
pagination.
* Decorator merged result for top and row
number
pagination.
*
*
* @author zhangliang
* @author zhangliang
*/
*/
...
@@ -47,7 +47,7 @@ public final class TopAndRowNumberDecoratorMergedResult extends DecoratorMergedR
...
@@ -47,7 +47,7 @@ public final class TopAndRowNumberDecoratorMergedResult extends DecoratorMergedR
if
(
null
==
limit
.
getOffset
())
{
if
(
null
==
limit
.
getOffset
())
{
end
=
0
;
end
=
0
;
}
else
{
}
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
++)
{
for
(
int
i
=
0
;
i
<
end
;
i
++)
{
if
(!
getMergedResult
().
next
())
{
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
...
@@ -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.dql.pagination.TopAndRowNumberDecoratorMergedResult
;
import
org.apache.shardingsphere.core.merge.fixture.TestQueryResult
;
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.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.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.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
...
@@ -91,14 +91,14 @@ public final class DQLMergeEngineTest {
...
@@ -91,14 +91,14 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildIteratorStreamMergedResultWithLimit
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
singleQueryResult
);
assertThat
(
mergeEngine
.
merge
(),
instanceOf
(
IteratorStreamMergedResult
.
class
));
assertThat
(
mergeEngine
.
merge
(),
instanceOf
(
IteratorStreamMergedResult
.
class
));
}
}
@Test
@Test
public
void
assertBuildIteratorStreamMergedResultWithMySQLLimit
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertThat
(
actual
,
instanceOf
(
LimitDecoratorMergedResult
.
class
));
assertThat
(
actual
,
instanceOf
(
LimitDecoratorMergedResult
.
class
));
...
@@ -107,7 +107,7 @@ public final class DQLMergeEngineTest {
...
@@ -107,7 +107,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildIteratorStreamMergedResultWithOracleLimit
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertThat
(
actual
,
instanceOf
(
RowNumberDecoratorMergedResult
.
class
));
assertThat
(
actual
,
instanceOf
(
RowNumberDecoratorMergedResult
.
class
));
...
@@ -116,7 +116,7 @@ public final class DQLMergeEngineTest {
...
@@ -116,7 +116,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildIteratorStreamMergedResultWithSQLServerLimit
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertThat
(
actual
,
instanceOf
(
TopAndRowNumberDecoratorMergedResult
.
class
));
assertThat
(
actual
,
instanceOf
(
TopAndRowNumberDecoratorMergedResult
.
class
));
...
@@ -132,7 +132,7 @@ public final class DQLMergeEngineTest {
...
@@ -132,7 +132,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildOrderByStreamMergedResultWithMySQLLimit
()
throws
SQLException
{
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
));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
...
@@ -142,7 +142,7 @@ public final class DQLMergeEngineTest {
...
@@ -142,7 +142,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildOrderByStreamMergedResultWithOracleLimit
()
throws
SQLException
{
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
));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
...
@@ -152,7 +152,7 @@ public final class DQLMergeEngineTest {
...
@@ -152,7 +152,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildOrderByStreamMergedResultWithSQLServerLimit
()
throws
SQLException
{
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
));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
...
@@ -170,7 +170,7 @@ public final class DQLMergeEngineTest {
...
@@ -170,7 +170,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildGroupByStreamMergedResultWithMySQLLimit
()
throws
SQLException
{
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
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
...
@@ -181,7 +181,7 @@ public final class DQLMergeEngineTest {
...
@@ -181,7 +181,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildGroupByStreamMergedResultWithOracleLimit
()
throws
SQLException
{
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
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
...
@@ -192,7 +192,7 @@ public final class DQLMergeEngineTest {
...
@@ -192,7 +192,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildGroupByStreamMergedResultWithSQLServerLimit
()
throws
SQLException
{
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
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
...
@@ -210,7 +210,7 @@ public final class DQLMergeEngineTest {
...
@@ -210,7 +210,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildGroupByMemoryMergedResultWithMySQLLimit
()
throws
SQLException
{
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
));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
...
@@ -220,7 +220,7 @@ public final class DQLMergeEngineTest {
...
@@ -220,7 +220,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildGroupByMemoryMergedResultWithOracleLimit
()
throws
SQLException
{
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
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
2
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
2
,
OrderDirection
.
DESC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
...
@@ -231,7 +231,7 @@ public final class DQLMergeEngineTest {
...
@@ -231,7 +231,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildGroupByMemoryMergedResultWithSQLServerLimit
()
throws
SQLException
{
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
.
DESC
,
OrderDirection
.
ASC
));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
ASC
,
OrderDirection
.
ASC
));
selectStatement
.
getGroupByItems
().
add
(
new
IndexOrderByItemSegment
(
0
,
0
,
1
,
OrderDirection
.
ASC
,
OrderDirection
.
ASC
));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
...
@@ -249,7 +249,7 @@ public final class DQLMergeEngineTest {
...
@@ -249,7 +249,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithMySQLLimit
()
throws
SQLException
{
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
()));
selectStatement
.
getItems
().
add
(
new
AggregationSelectItem
(
AggregationType
.
COUNT
,
"(*)"
,
Optional
.<
String
>
absent
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
...
@@ -259,7 +259,7 @@ public final class DQLMergeEngineTest {
...
@@ -259,7 +259,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLimit
()
throws
SQLException
{
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
()));
selectStatement
.
getItems
().
add
(
new
AggregationSelectItem
(
AggregationType
.
COUNT
,
"(*)"
,
Optional
.<
String
>
absent
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
...
@@ -269,7 +269,7 @@ public final class DQLMergeEngineTest {
...
@@ -269,7 +269,7 @@ public final class DQLMergeEngineTest {
@Test
@Test
public
void
assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithSQLServerLimit
()
throws
SQLException
{
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
()));
selectStatement
.
getItems
().
add
(
new
AggregationSelectItem
(
AggregationType
.
COUNT
,
"(*)"
,
Optional
.<
String
>
absent
()));
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
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;
...
@@ -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.MergedResult
;
import
org.apache.shardingsphere.core.merge.dql.DQLMergeEngine
;
import
org.apache.shardingsphere.core.merge.dql.DQLMergeEngine
;
import
org.apache.shardingsphere.core.merge.fixture.TestQueryResult
;
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.
pagination.Pagination
Segment
;
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.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
...
@@ -66,12 +66,12 @@ public final class LimitDecoratorMergedResultTest {
...
@@ -66,12 +66,12 @@ public final class LimitDecoratorMergedResultTest {
}
}
SelectStatement
selectStatement
=
new
SelectStatement
();
SelectStatement
selectStatement
=
new
SelectStatement
();
routeResult
=
new
SQLRouteResult
(
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
@Test
public
void
assertNextForSkipAll
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertFalse
(
actual
.
next
());
assertFalse
(
actual
.
next
());
...
@@ -79,7 +79,7 @@ public final class LimitDecoratorMergedResultTest {
...
@@ -79,7 +79,7 @@ public final class LimitDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextWithoutRowCount
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
...
@@ -90,7 +90,7 @@ public final class LimitDecoratorMergedResultTest {
...
@@ -90,7 +90,7 @@ public final class LimitDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextWithRowCount
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
MySQL
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
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;
...
@@ -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.MergedResult
;
import
org.apache.shardingsphere.core.merge.dql.DQLMergeEngine
;
import
org.apache.shardingsphere.core.merge.dql.DQLMergeEngine
;
import
org.apache.shardingsphere.core.merge.fixture.TestQueryResult
;
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.
pagination.Pagination
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimit
ValueSegment
;
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.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
...
@@ -69,7 +69,7 @@ public final class RowNumberDecoratorMergedResultTest {
...
@@ -69,7 +69,7 @@ public final class RowNumberDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextForSkipAll
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertFalse
(
actual
.
next
());
assertFalse
(
actual
.
next
());
...
@@ -77,7 +77,7 @@ public final class RowNumberDecoratorMergedResultTest {
...
@@ -77,7 +77,7 @@ public final class RowNumberDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextWithoutOffsetWithoutRowCount
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
...
@@ -88,7 +88,8 @@ public final class RowNumberDecoratorMergedResultTest {
...
@@ -88,7 +88,8 @@ public final class RowNumberDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextForRowCountBoundOpenedFalse
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
assertTrue
(
actual
.
next
());
...
@@ -98,7 +99,8 @@ public final class RowNumberDecoratorMergedResultTest {
...
@@ -98,7 +99,8 @@ public final class RowNumberDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextForRowCountBoundOpenedTrue
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
Oracle
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
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;
...
@@ -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.MergedResult
;
import
org.apache.shardingsphere.core.merge.dql.DQLMergeEngine
;
import
org.apache.shardingsphere.core.merge.dql.DQLMergeEngine
;
import
org.apache.shardingsphere.core.merge.fixture.TestQueryResult
;
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.pagination.PaginationSegment
;
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.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.SQLRouteResult
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
import
org.apache.shardingsphere.core.route.limit.Limit
;
...
@@ -49,8 +50,6 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
...
@@ -49,8 +50,6 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
private
List
<
QueryResult
>
queryResults
;
private
List
<
QueryResult
>
queryResults
;
private
SelectStatement
selectStatement
;
private
SQLRouteResult
routeResult
;
private
SQLRouteResult
routeResult
;
@Before
@Before
...
@@ -66,13 +65,12 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
...
@@ -66,13 +65,12 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
for
(
ResultSet
each
:
resultSets
)
{
for
(
ResultSet
each
:
resultSets
)
{
queryResults
.
add
(
new
TestQueryResult
(
each
));
queryResults
.
add
(
new
TestQueryResult
(
each
));
}
}
selectStatement
=
new
SelectStatement
();
routeResult
=
new
SQLRouteResult
(
new
SelectStatement
());
routeResult
=
new
SQLRouteResult
(
selectStatement
);
}
}
@Test
@Test
public
void
assertNextForSkipAll
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertFalse
(
actual
.
next
());
assertFalse
(
actual
.
next
());
...
@@ -80,7 +78,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
...
@@ -80,7 +78,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextWithoutOffsetWithRowCount
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
...
@@ -91,7 +89,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
...
@@ -91,7 +89,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextWithOffsetWithoutRowCount
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
for
(
int
i
=
0
;
i
<
7
;
i
++)
{
for
(
int
i
=
0
;
i
<
7
;
i
++)
{
...
@@ -102,7 +100,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
...
@@ -102,7 +100,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextWithOffsetBoundOpenedFalse
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
assertTrue
(
actual
.
next
());
...
@@ -112,7 +110,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
...
@@ -112,7 +110,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest {
@Test
@Test
public
void
assertNextWithOffsetBoundOpenedTrue
()
throws
SQLException
{
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
);
mergeEngine
=
new
DQLMergeEngine
(
DatabaseType
.
SQLServer
,
routeResult
,
queryResults
);
MergedResult
actual
=
mergeEngine
.
merge
();
MergedResult
actual
=
mergeEngine
.
merge
();
assertTrue
(
actual
.
next
());
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
...
@@ -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.ExtractorUtils
;
import
org.apache.shardingsphere.core.parse.extractor.util.RuleName
;
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.expr.simple.ParameterMarkerExpressionSegment
;
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.segment.dml.limit.LimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.LimitValueSegment
;
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.segment.dml.limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.core.util.NumberUtil
;
import
org.apache.shardingsphere.core.util.NumberUtil
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -45,11 +45,11 @@ public final class LimitExtractor implements OptionalSQLSegmentExtractor {
...
@@ -45,11 +45,11 @@ public final class LimitExtractor implements OptionalSQLSegmentExtractor {
private
final
ParameterMarkerExpressionExtractor
parameterMarkerExpressionExtractor
=
new
ParameterMarkerExpressionExtractor
();
private
final
ParameterMarkerExpressionExtractor
parameterMarkerExpressionExtractor
=
new
ParameterMarkerExpressionExtractor
();
@Override
@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
);
Optional
<
ParserRuleContext
>
limitNode
=
ExtractorUtils
.
findFirstChildNode
(
ancestorNode
,
RuleName
.
LIMIT_CLAUSE
);
return
limitNode
.
isPresent
()
return
limitNode
.
isPresent
()
?
Optional
.
of
(
new
Limit
Segment
(
limitNode
.
get
().
getStart
().
getStartIndex
(),
limitNode
.
get
().
getStop
().
getStopIndex
(),
?
Optional
.
of
(
new
Pagination
Segment
(
limitNode
.
get
().
getStart
().
getStartIndex
(),
limitNode
.
get
().
getStop
().
getStopIndex
(),
extractOffset
(
limitNode
.
get
(),
parameterMarkerIndexes
).
orNull
(),
extractRowCount
(
limitNode
.
get
(),
parameterMarkerIndexes
).
orNull
()))
:
Optional
.<
Limit
Segment
>
absent
();
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
)
{
private
Optional
<
LimitValueSegment
>
extractOffset
(
final
ParserRuleContext
limitNode
,
final
Map
<
ParserRuleContext
,
Integer
>
parameterMarkerIndexes
)
{
...
@@ -66,11 +66,11 @@ public final class LimitExtractor implements OptionalSQLSegmentExtractor {
...
@@ -66,11 +66,11 @@ public final class LimitExtractor implements OptionalSQLSegmentExtractor {
Optional
<
ParameterMarkerExpressionSegment
>
parameterMarkerExpression
=
parameterMarkerExpressionExtractor
.
extract
(
limitValueNode
,
parameterMarkerIndexes
);
Optional
<
ParameterMarkerExpressionSegment
>
parameterMarkerExpression
=
parameterMarkerExpressionExtractor
.
extract
(
limitValueNode
,
parameterMarkerIndexes
);
if
(
parameterMarkerExpression
.
isPresent
())
{
if
(
parameterMarkerExpression
.
isPresent
())
{
return
new
ParameterMarkerLimitValueSegment
(
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
);
Optional
<
ParserRuleContext
>
numberLiteralsNode
=
ExtractorUtils
.
findFirstChildNode
(
limitValueNode
,
RuleName
.
NUMBER_LITERALS
);
Preconditions
.
checkState
(
numberLiteralsNode
.
isPresent
());
Preconditions
.
checkState
(
numberLiteralsNode
.
isPresent
());
return
new
NumberLiteralLimitValueSegment
(
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;
...
@@ -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.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment
;
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.expr.simple.ParameterMarkerExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.LimitValueSegment
;
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.segment.dml.limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.
limit.ParameterMarkerLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit
.TopSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.top
.TopSegment
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -62,11 +62,11 @@ public final class TopSelectItemExtractor implements OptionalSQLSegmentExtractor
...
@@ -62,11 +62,11 @@ public final class TopSelectItemExtractor implements OptionalSQLSegmentExtractor
private
Optional
<
LimitValueSegment
>
createLimitValueSegment
(
final
ExpressionSegment
topExpr
)
{
private
Optional
<
LimitValueSegment
>
createLimitValueSegment
(
final
ExpressionSegment
topExpr
)
{
if
(
topExpr
instanceof
ParameterMarkerExpressionSegment
)
{
if
(
topExpr
instanceof
ParameterMarkerExpressionSegment
)
{
return
Optional
.<
LimitValueSegment
>
of
(
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
)
{
if
(
topExpr
instanceof
LiteralExpressionSegment
&&
((
LiteralExpressionSegment
)
topExpr
).
getLiterals
()
instanceof
Number
)
{
return
Optional
.<
LimitValueSegment
>
of
(
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
();
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 @@
...
@@ -18,7 +18,7 @@
package
org.apache.shardingsphere.core.parse.filler.common.dml
;
package
org.apache.shardingsphere.core.parse.filler.common.dml
;
import
org.apache.shardingsphere.core.parse.filler.api.SQLSegmentFiller
;
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.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
...
@@ -27,10 +27,10 @@ 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
* @author duhongjun
*/
*/
public
final
class
LimitFiller
implements
SQLSegmentFiller
<
Limit
Segment
>
{
public
final
class
LimitFiller
implements
SQLSegmentFiller
<
Pagination
Segment
>
{
@Override
@Override
public
void
fill
(
final
Limit
Segment
sqlSegment
,
final
SQLStatement
sqlStatement
)
{
public
void
fill
(
final
Pagination
Segment
sqlSegment
,
final
SQLStatement
sqlStatement
)
{
((
SelectStatement
)
sqlStatement
).
set
Limit
(
sqlSegment
);
((
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
...
@@ -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.ExpressionSelectItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemSegment
;
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.item.ShorthandSelectItemSegment
;
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.segment.dml.
limit
.TopSegment
;
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.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
...
@@ -109,7 +109,7 @@ public final class SelectItemFiller implements SQLSegmentFiller<SelectItemSegmen
...
@@ -109,7 +109,7 @@ public final class SelectItemFiller implements SQLSegmentFiller<SelectItemSegmen
}
}
private
void
fillTopSegment
(
final
TopSegment
topSegment
,
final
SelectStatement
selectStatement
)
{
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
())));
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;
...
@@ -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.ExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment
;
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.expr.simple.ParameterMarkerExpressionSegment
;
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.segment.dml.
limit.Limit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.rownum.NumberLiteralRowNumber
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.rownum.ParameterMarkerRowNumber
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.ParameterMarkerLimit
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.AndPredicate
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.OrPredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.OrPredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment
;
...
@@ -98,34 +98,34 @@ public final class ShardingRowNumberPredicateFiller implements SQLSegmentFiller<
...
@@ -98,34 +98,34 @@ public final class ShardingRowNumberPredicateFiller implements SQLSegmentFiller<
}
}
private
void
fillLimit
(
final
SelectStatement
selectStatement
,
final
Collection
<
PredicateSegment
>
rowNumberPredicates
)
{
private
void
fillLimit
(
final
SelectStatement
selectStatement
,
final
Collection
<
PredicateSegment
>
rowNumberPredicates
)
{
Limit
ValueSegment
rowCount
=
null
;
RowNumber
ValueSegment
rowCount
=
null
;
Limit
ValueSegment
offset
=
null
;
RowNumber
ValueSegment
offset
=
null
;
for
(
PredicateSegment
each
:
rowNumberPredicates
)
{
for
(
PredicateSegment
each
:
rowNumberPredicates
)
{
ExpressionSegment
expression
=
((
PredicateCompareRightValue
)
each
.
getRightValue
()).
getExpression
();
ExpressionSegment
expression
=
((
PredicateCompareRightValue
)
each
.
getRightValue
()).
getExpression
();
switch
(((
PredicateCompareRightValue
)
each
.
getRightValue
()).
getOperator
())
{
switch
(((
PredicateCompareRightValue
)
each
.
getRightValue
()).
getOperator
())
{
case
">"
:
case
">"
:
offset
=
create
Limit
ValueSegment
(
expression
,
false
);
offset
=
create
RowNumber
ValueSegment
(
expression
,
false
);
break
;
break
;
case
">="
:
case
">="
:
offset
=
create
Limit
ValueSegment
(
expression
,
true
);
offset
=
create
RowNumber
ValueSegment
(
expression
,
true
);
break
;
break
;
case
"<"
:
case
"<"
:
rowCount
=
create
Limit
ValueSegment
(
expression
,
false
);
rowCount
=
create
RowNumber
ValueSegment
(
expression
,
false
);
break
;
break
;
case
"<="
:
case
"<="
:
rowCount
=
create
Limit
ValueSegment
(
expression
,
true
);
rowCount
=
create
RowNumber
ValueSegment
(
expression
,
true
);
break
;
break
;
default
:
default
:
break
;
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
)
{
private
RowNumberValueSegment
createRowNumber
ValueSegment
(
final
ExpressionSegment
expression
,
final
boolean
boundOpened
)
{
if
(
expression
instanceof
LiteralExpressionSegment
)
{
return
expression
instanceof
LiteralExpressionSegment
return
new
NumberLiteralLimitValueSegment
(
expression
.
getStartIndex
(),
expression
.
getStopIndex
(),
(
Integer
)
((
LiteralExpressionSegment
)
expression
).
getLiterals
(),
boundOpened
);
?
new
NumberLiteralRowNumberValueSegment
(
expression
.
getStartIndex
(),
expression
.
getStopIndex
(),
(
int
)
((
LiteralExpressionSegment
)
expression
).
getLiterals
(),
boundOpened
)
}
:
new
ParameterMarkerRowNumberValueSegment
(
return
new
ParameterMarkerLimitValueSegment
(
expression
.
getStartIndex
(),
expression
.
getStopIndex
(),
((
ParameterMarkerExpressionSegment
)
expression
).
getParameterMarkerIndex
(),
boundOpened
);
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 @@
...
@@ -15,11 +15,12 @@
* limitations under the License.
* 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.Getter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemSegment
;
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.
* 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
...
@@ -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.SelectItem
;
import
org.apache.shardingsphere.core.parse.sql.context.selectitem.StarSelectItem
;
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.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.ColumnOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ExpressionOrderByItemSegment
;
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.IndexOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.OrderByItemSegment
;
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.order.item.TextOrderByItemSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment
;
import
org.apache.shardingsphere.core.parse.util.SQLUtil
;
import
org.apache.shardingsphere.core.parse.util.SQLUtil
;
import
java.util.Collection
;
import
java.util.Collection
;
...
@@ -71,7 +71,7 @@ public final class SelectStatement extends DQLStatement {
...
@@ -71,7 +71,7 @@ public final class SelectStatement extends DQLStatement {
private
int
groupByLastIndex
;
private
int
groupByLastIndex
;
private
LimitSegment
limit
;
private
PaginationSegment
pagination
;
private
SelectStatement
parentStatement
;
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 @@
...
@@ -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.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.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.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
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>
</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
...
@@ -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.groupby.GroupByAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.index.IndexAssert
;
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.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.meta.TableMetaDataAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.orderby.OrderByAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.orderby.OrderByAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.table.AlterTableAssert
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.table.AlterTableAssert
;
...
@@ -61,7 +61,7 @@ public final class SQLStatementAssert {
...
@@ -61,7 +61,7 @@ public final class SQLStatementAssert {
private
final
OrderByAssert
orderByAssert
;
private
final
OrderByAssert
orderByAssert
;
private
final
LimitAssert
limit
Assert
;
private
final
PaginationAssert
pagination
Assert
;
private
final
TableMetaDataAssert
metaAssert
;
private
final
TableMetaDataAssert
metaAssert
;
...
@@ -84,7 +84,7 @@ public final class SQLStatementAssert {
...
@@ -84,7 +84,7 @@ public final class SQLStatementAssert {
itemAssert
=
new
ItemAssert
(
assertMessage
);
itemAssert
=
new
ItemAssert
(
assertMessage
);
groupByAssert
=
new
GroupByAssert
(
assertMessage
);
groupByAssert
=
new
GroupByAssert
(
assertMessage
);
orderByAssert
=
new
OrderByAssert
(
assertMessage
);
orderByAssert
=
new
OrderByAssert
(
assertMessage
);
limitAssert
=
new
Limit
Assert
(
sqlCaseType
,
assertMessage
);
paginationAssert
=
new
Pagination
Assert
(
sqlCaseType
,
assertMessage
);
metaAssert
=
new
TableMetaDataAssert
(
assertMessage
);
metaAssert
=
new
TableMetaDataAssert
(
assertMessage
);
alterTableAssert
=
new
AlterTableAssert
(
assertMessage
);
alterTableAssert
=
new
AlterTableAssert
(
assertMessage
);
this
.
databaseType
=
databaseType
;
this
.
databaseType
=
databaseType
;
...
@@ -118,7 +118,7 @@ public final class SQLStatementAssert {
...
@@ -118,7 +118,7 @@ public final class SQLStatementAssert {
itemAssert
.
assertItems
(
actual
.
getItems
(),
expected
.
getSelectItems
());
itemAssert
.
assertItems
(
actual
.
getItems
(),
expected
.
getSelectItems
());
groupByAssert
.
assertGroupByItems
(
actual
.
getGroupByItems
(),
expected
.
getGroupByColumns
());
groupByAssert
.
assertGroupByItems
(
actual
.
getGroupByItems
(),
expected
.
getGroupByColumns
());
orderByAssert
.
assertOrderByItems
(
actual
.
getOrderByItems
(),
expected
.
getOrderByColumns
());
orderByAssert
.
assertOrderByItems
(
actual
.
getOrderByItems
(),
expected
.
getOrderByColumns
());
limitAssert
.
assertLimit
(
actual
.
getLimit
(),
expected
.
getLimit
());
paginationAssert
.
assertPagination
(
actual
.
getPagination
(),
expected
.
getLimit
());
}
}
private
void
assertCreateTableStatement
(
final
CreateTableStatement
actual
)
{
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;
...
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.core.parse.integrate.asserts.limit;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.integrate.asserts.SQLStatementAssertMessage
;
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.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.
pagination.NumberLiteralPaginationValue
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimitValue
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.Pagination
Segment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.ParameterMarkerLimit
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
pagination.ParameterMarkerPagination
ValueSegment
;
import
org.apache.shardingsphere.test.sql.SQLCaseType
;
import
org.apache.shardingsphere.test.sql.SQLCaseType
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
...
@@ -30,45 +30,45 @@ import static org.junit.Assert.assertNull;
...
@@ -30,45 +30,45 @@ import static org.junit.Assert.assertNull;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
/**
*
Limit
assert.
*
Pagination
assert.
*
*
* @author zhangliang
* @author zhangliang
*/
*/
@RequiredArgsConstructor
@RequiredArgsConstructor
public
final
class
Limit
Assert
{
public
final
class
Pagination
Assert
{
private
final
SQLCaseType
sqlCaseType
;
private
final
SQLCaseType
sqlCaseType
;
private
final
SQLStatementAssertMessage
assertMessage
;
private
final
SQLStatementAssertMessage
assertMessage
;
/**
/**
* Assert
limit
.
* Assert
pagination
.
*
*
* @param actual actual
limit
* @param actual actual
pagination
* @param expected expected
limit
* @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
)
{
if
(
null
==
actual
)
{
assertNull
(
assertMessage
.
getFullAssertMessage
(
"
Limit
should not exist: "
),
expected
);
assertNull
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
should not exist: "
),
expected
);
return
;
return
;
}
}
if
(
SQLCaseType
.
Placeholder
==
sqlCaseType
)
{
if
(
SQLCaseType
.
Placeholder
==
sqlCaseType
)
{
if
(
actual
.
getOffset
().
isPresent
())
{
if
(
actual
.
getOffset
().
isPresent
())
{
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Limit
offset index assertion error: "
),
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
offset index assertion error: "
),
((
ParameterMarker
Limit
ValueSegment
)
actual
.
getOffset
().
get
()).
getParameterIndex
(),
is
(
expected
.
getOffsetParameterIndex
()));
((
ParameterMarker
Pagination
ValueSegment
)
actual
.
getOffset
().
get
()).
getParameterIndex
(),
is
(
expected
.
getOffsetParameterIndex
()));
}
}
if
(
actual
.
getRowCount
().
isPresent
())
{
if
(
actual
.
getRowCount
().
isPresent
())
{
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Limit
row count index assertion error: "
),
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
row count index assertion error: "
),
((
ParameterMarker
Limit
ValueSegment
)
actual
.
getRowCount
().
get
()).
getParameterIndex
(),
is
(
expected
.
getRowCountParameterIndex
()));
((
ParameterMarker
Pagination
ValueSegment
)
actual
.
getRowCount
().
get
()).
getParameterIndex
(),
is
(
expected
.
getRowCountParameterIndex
()));
}
}
}
else
{
}
else
{
if
(
actual
.
getOffset
().
isPresent
())
{
if
(
actual
.
getOffset
().
isPresent
())
{
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Limit
offset value assertion error: "
),
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
offset value assertion error: "
),
((
NumberLiteral
Limit
ValueSegment
)
actual
.
getOffset
().
get
()).
getValue
(),
is
(
expected
.
getOffset
()));
((
NumberLiteral
Pagination
ValueSegment
)
actual
.
getOffset
().
get
()).
getValue
(),
is
(
expected
.
getOffset
()));
}
}
if
(
actual
.
getRowCount
().
isPresent
())
{
if
(
actual
.
getRowCount
().
isPresent
())
{
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Limit
row count value assertion error: "
),
assertThat
(
assertMessage
.
getFullAssertMessage
(
"
Pagination
row count value assertion error: "
),
((
NumberLiteral
Limit
ValueSegment
)
actual
.
getRowCount
().
get
()).
getValue
(),
is
(
expected
.
getRowCount
()));
((
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 @@
...
@@ -18,8 +18,8 @@
package
org.apache.shardingsphere.core.rewrite.token.generator
;
package
org.apache.shardingsphere.core.rewrite.token.generator
;
import
com.google.common.base.Optional
;
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.
pagination.NumberLiteralPagination
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimit
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.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.OffsetToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.OffsetToken
;
...
@@ -37,17 +37,18 @@ public final class OffsetTokenGenerator implements OptionalSQLTokenGenerator<Sha
...
@@ -37,17 +37,18 @@ public final class OffsetTokenGenerator implements OptionalSQLTokenGenerator<Sha
if
(!(
sqlStatement
instanceof
SelectStatement
))
{
if
(!(
sqlStatement
instanceof
SelectStatement
))
{
return
Optional
.
absent
();
return
Optional
.
absent
();
}
}
Optional
<
Limit
ValueSegment
>
offsetSegment
=
getLiteralOffsetSegment
((
SelectStatement
)
sqlStatement
);
Optional
<
Pagination
ValueSegment
>
offsetSegment
=
getLiteralOffsetSegment
((
SelectStatement
)
sqlStatement
);
return
offsetSegment
.
isPresent
()
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
();
:
Optional
.<
OffsetToken
>
absent
();
}
}
private
Optional
<
Limit
ValueSegment
>
getLiteralOffsetSegment
(
final
SelectStatement
selectStatement
)
{
private
Optional
<
Pagination
ValueSegment
>
getLiteralOffsetSegment
(
final
SelectStatement
selectStatement
)
{
return
isLiteralOffset
(
selectStatement
)
?
selectStatement
.
get
Limit
().
getOffset
()
:
Optional
.<
Limit
ValueSegment
>
absent
();
return
isLiteralOffset
(
selectStatement
)
?
selectStatement
.
get
Pagination
().
getOffset
()
:
Optional
.<
Pagination
ValueSegment
>
absent
();
}
}
private
boolean
isLiteralOffset
(
final
SelectStatement
selectStatement
)
{
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 @@
...
@@ -18,8 +18,8 @@
package
org.apache.shardingsphere.core.rewrite.token.generator
;
package
org.apache.shardingsphere.core.rewrite.token.generator
;
import
com.google.common.base.Optional
;
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.
pagination.NumberLiteralPagination
ValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.
limit.NumberLiteralLimit
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.SQLStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.RowCountToken
;
import
org.apache.shardingsphere.core.rewrite.token.pojo.RowCountToken
;
...
@@ -37,17 +37,18 @@ public final class RowCountTokenGenerator implements OptionalSQLTokenGenerator<S
...
@@ -37,17 +37,18 @@ public final class RowCountTokenGenerator implements OptionalSQLTokenGenerator<S
if
(!(
sqlStatement
instanceof
SelectStatement
))
{
if
(!(
sqlStatement
instanceof
SelectStatement
))
{
return
Optional
.
absent
();
return
Optional
.
absent
();
}
}
Optional
<
Limit
ValueSegment
>
rowCountSegment
=
getLiteralRowCountSegment
((
SelectStatement
)
sqlStatement
);
Optional
<
Pagination
ValueSegment
>
rowCountSegment
=
getLiteralRowCountSegment
((
SelectStatement
)
sqlStatement
);
return
rowCountSegment
.
isPresent
()
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
();
:
Optional
.<
RowCountToken
>
absent
();
}
}
private
Optional
<
Limit
ValueSegment
>
getLiteralRowCountSegment
(
final
SelectStatement
selectStatement
)
{
private
Optional
<
Pagination
ValueSegment
>
getLiteralRowCountSegment
(
final
SelectStatement
selectStatement
)
{
return
isLiteralRowCount
(
selectStatement
)
?
selectStatement
.
get
Limit
().
getRowCount
()
:
Optional
.<
Limit
ValueSegment
>
absent
();
return
isLiteralRowCount
(
selectStatement
)
?
selectStatement
.
get
Pagination
().
getRowCount
()
:
Optional
.<
Pagination
ValueSegment
>
absent
();
}
}
private
boolean
isLiteralRowCount
(
final
SelectStatement
selectStatement
)
{
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;
...
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.Getter
;
import
lombok.Getter
;
/**
/**
* Offset token for
limit
.
* Offset token for
pagination
.
*
*
* @author zhangliang
* @author zhangliang
* @author panjuan
* @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;
...
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.core.rewrite.token.pojo;
import
lombok.Getter
;
import
lombok.Getter
;
/**
/**
* Row count token for
limit
.
* Row count token for
pagination
.
*
*
* @author zhangliang
* @author zhangliang
* @author panjuan
* @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
...
@@ -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.LiteralExpressionSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment
;
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.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.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.segment.dml.predicate.PredicateSegment
;
import
org.apache.shardingsphere.core.parse.sql.statement.dal.DALStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dal.DALStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.DeleteStatement
;
import
org.apache.shardingsphere.core.parse.sql.statement.dml.DeleteStatement
;
...
@@ -346,8 +347,8 @@ public final class ShardingSQLRewriterTest {
...
@@ -346,8 +347,8 @@ public final class ShardingSQLRewriterTest {
@Test
@Test
public
void
assertRewriteForLimit
()
{
public
void
assertRewriteForLimit
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
,
false
));
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
));
selectStatement
.
set
Limit
(
limitSegment
);
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
17
,
23
,
"table_x"
));
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
17
,
23
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
@@ -358,9 +359,9 @@ public final class ShardingSQLRewriterTest {
...
@@ -358,9 +359,9 @@ public final class ShardingSQLRewriterTest {
}
}
@Test
@Test
public
void
assertRewriteForRowNum
()
{
public
void
assertRewriteForRowNum
ber
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralLimit
ValueSegment
(
98
,
98
,
4
,
false
));
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralRowNumber
ValueSegment
(
98
,
98
,
4
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
68
,
74
,
"table_x"
));
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
68
,
74
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
@@ -373,8 +374,8 @@ public final class ShardingSQLRewriterTest {
...
@@ -373,8 +374,8 @@ public final class ShardingSQLRewriterTest {
@Test
@Test
public
void
assertRewriteForTopAndRowNumber
()
{
public
void
assertRewriteForTopAndRowNumber
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
,
false
));
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
));
selectStatement
.
set
Limit
(
limitSegment
);
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
85
,
91
,
"table_x"
));
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
85
,
91
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
@@ -387,8 +388,8 @@ public final class ShardingSQLRewriterTest {
...
@@ -387,8 +388,8 @@ public final class ShardingSQLRewriterTest {
@Test
@Test
public
void
assertRewriteForLimitForMemoryGroupBy
()
{
public
void
assertRewriteForLimitForMemoryGroupBy
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
,
false
));
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
));
selectStatement
.
set
Limit
(
limitSegment
);
selectStatement
.
set
Pagination
(
limitSegment
);
ColumnSegment
columnSegment
=
new
ColumnSegment
(
0
,
0
,
"id"
);
ColumnSegment
columnSegment
=
new
ColumnSegment
(
0
,
0
,
"id"
);
columnSegment
.
setOwner
(
new
TableSegment
(
0
,
0
,
"x"
));
columnSegment
.
setOwner
(
new
TableSegment
(
0
,
0
,
"x"
));
selectStatement
.
getOrderByItems
().
add
(
new
ColumnOrderByItemSegment
(
0
,
0
,
columnSegment
,
OrderDirection
.
ASC
,
OrderDirection
.
ASC
));
selectStatement
.
getOrderByItems
().
add
(
new
ColumnOrderByItemSegment
(
0
,
0
,
columnSegment
,
OrderDirection
.
ASC
,
OrderDirection
.
ASC
));
...
@@ -404,8 +405,8 @@ public final class ShardingSQLRewriterTest {
...
@@ -404,8 +405,8 @@ public final class ShardingSQLRewriterTest {
@Test
@Test
public
void
assertRewriteForRowNumForMemoryGroupBy
()
{
public
void
assertRewriteForRowNumForMemoryGroupBy
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralLimit
ValueSegment
(
98
,
98
,
4
,
false
));
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralRowNumber
ValueSegment
(
98
,
98
,
4
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
68
,
74
,
"table_x"
));
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
68
,
74
,
"table_x"
));
ColumnSegment
columnSegment
=
new
ColumnSegment
(
0
,
0
,
"id"
);
ColumnSegment
columnSegment
=
new
ColumnSegment
(
0
,
0
,
"id"
);
columnSegment
.
setOwner
(
new
TableSegment
(
0
,
0
,
"x"
));
columnSegment
.
setOwner
(
new
TableSegment
(
0
,
0
,
"x"
));
...
@@ -422,8 +423,8 @@ public final class ShardingSQLRewriterTest {
...
@@ -422,8 +423,8 @@ public final class ShardingSQLRewriterTest {
@Test
@Test
public
void
assertRewriteForTopAndRowNumberForMemoryGroupBy
()
{
public
void
assertRewriteForTopAndRowNumberForMemoryGroupBy
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
,
false
));
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
123
,
123
,
2
,
false
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
));
selectStatement
.
set
Limit
(
limitSegment
);
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
85
,
91
,
"table_x"
));
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
85
,
91
,
"table_x"
));
ColumnSegment
columnSegment
=
new
ColumnSegment
(
0
,
0
,
"id"
);
ColumnSegment
columnSegment
=
new
ColumnSegment
(
0
,
0
,
"id"
);
columnSegment
.
setOwner
(
new
TableSegment
(
0
,
0
,
"x"
));
columnSegment
.
setOwner
(
new
TableSegment
(
0
,
0
,
"x"
));
...
@@ -440,8 +441,8 @@ public final class ShardingSQLRewriterTest {
...
@@ -440,8 +441,8 @@ public final class ShardingSQLRewriterTest {
@Test
@Test
public
void
assertRewriteForLimitForNotRewriteLimit
()
{
public
void
assertRewriteForLimitForNotRewriteLimit
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
,
false
));
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
33
,
33
,
2
),
new
NumberLiteralLimitValueSegment
(
36
,
36
,
2
));
selectStatement
.
set
Limit
(
limitSegment
);
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
17
,
23
,
"table_x"
));
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
17
,
23
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
@@ -455,8 +456,8 @@ public final class ShardingSQLRewriterTest {
...
@@ -455,8 +456,8 @@ public final class ShardingSQLRewriterTest {
@Test
@Test
public
void
assertRewriteForRowNumForNotRewriteLimit
()
{
public
void
assertRewriteForRowNumForNotRewriteLimit
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralLimit
ValueSegment
(
98
,
98
,
4
,
false
));
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
119
,
119
,
2
,
true
),
new
NumberLiteralRowNumber
ValueSegment
(
98
,
98
,
4
,
false
));
selectStatement
.
set
Limit
(
limitSegment
);
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
68
,
74
,
"table_x"
));
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
68
,
74
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
...
@@ -471,8 +472,8 @@ public final class ShardingSQLRewriterTest {
...
@@ -471,8 +472,8 @@ public final class ShardingSQLRewriterTest {
@Test
@Test
public
void
assertRewriteForTopAndRowNumberForNotRewriteLimit
()
{
public
void
assertRewriteForTopAndRowNumberForNotRewriteLimit
()
{
LimitSegment
limitSegment
=
new
LimitSegment
(
0
,
0
,
new
NumberLiteralLimitValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
,
false
));
PaginationSegment
limitSegment
=
new
PaginationSegment
(
0
,
0
,
new
NumberLiteralRowNumberValueSegment
(
123
,
123
,
2
,
true
),
new
NumberLiteralLimitValueSegment
(
26
,
26
,
4
));
selectStatement
.
set
Limit
(
limitSegment
);
selectStatement
.
set
Pagination
(
limitSegment
);
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
85
,
91
,
"table_x"
));
selectStatement
.
getSqlSegments
().
add
(
new
TableSegment
(
85
,
91
,
"table_x"
));
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
=
new
SQLRouteResult
(
selectStatement
);
routeResult
.
setLimit
(
new
Limit
(
limitSegment
,
Collections
.
emptyList
()));
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 @@
...
@@ -18,10 +18,11 @@
package
org.apache.shardingsphere.core.route.limit
;
package
org.apache.shardingsphere.core.route.limit
;
import
lombok.Getter
;
import
lombok.Getter
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.ParameterMarkerLimitValueSegment
;
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.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -41,15 +42,16 @@ public final class Limit {
...
@@ -41,15 +42,16 @@ public final class Limit {
private
final
LimitValue
rowCount
;
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
;
offset
=
limitSegment
.
getOffset
().
isPresent
()
?
createLimitValue
(
limitSegment
.
getOffset
().
get
(),
parameters
)
:
null
;
rowCount
=
limitSegment
.
getRowCount
().
isPresent
()
?
createLimitValue
(
limitSegment
.
getRowCount
().
get
(),
parameters
)
:
null
;
rowCount
=
limitSegment
.
getRowCount
().
isPresent
()
?
createLimitValue
(
limitSegment
.
getRowCount
().
get
(),
parameters
)
:
null
;
}
}
private
LimitValue
createLimitValue
(
final
LimitValueSegment
limitValueSegment
,
final
List
<
Object
>
parameters
)
{
private
LimitValue
createLimitValue
(
final
PaginationValueSegment
paginationValueSegment
,
final
List
<
Object
>
parameters
)
{
int
segmentValue
=
limitValueSegment
instanceof
ParameterMarkerLimitValueSegment
int
segmentValue
=
paginationValueSegment
instanceof
ParameterMarkerPaginationValueSegment
?
(
int
)
parameters
.
get
(((
ParameterMarkerLimitValueSegment
)
limitValueSegment
).
getParameterIndex
())
:
((
NumberLiteralLimitValueSegment
)
limitValueSegment
).
getValue
();
?
(
int
)
parameters
.
get
(((
ParameterMarkerPaginationValueSegment
)
paginationValueSegment
).
getParameterIndex
())
return
new
LimitValue
(
limitValueSegment
,
segmentValue
);
:
((
NumberLiteralPaginationValueSegment
)
paginationValueSegment
).
getValue
();
return
new
LimitValue
(
paginationValueSegment
,
segmentValue
);
}
}
/**
/**
...
@@ -79,11 +81,11 @@ public final class Limit {
...
@@ -79,11 +81,11 @@ public final class Limit {
*/
*/
public
Map
<
Integer
,
Object
>
getRevisedParameters
(
final
boolean
isFetchAll
,
final
String
databaseType
)
{
public
Map
<
Integer
,
Object
>
getRevisedParameters
(
final
boolean
isFetchAll
,
final
String
databaseType
)
{
Map
<
Integer
,
Object
>
result
=
new
HashMap
<>(
2
,
1
);
Map
<
Integer
,
Object
>
result
=
new
HashMap
<>(
2
,
1
);
if
(
null
!=
offset
&&
offset
.
get
Limit
ValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
if
(
null
!=
offset
&&
offset
.
get
Pagination
ValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
result
.
put
(((
ParameterMarkerLimitValueSegment
)
offset
.
get
Limit
ValueSegment
()).
getParameterIndex
(),
0
);
result
.
put
(((
ParameterMarkerLimitValueSegment
)
offset
.
get
Pagination
ValueSegment
()).
getParameterIndex
(),
0
);
}
}
if
(
null
!=
rowCount
&&
rowCount
.
get
Limit
ValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
if
(
null
!=
rowCount
&&
rowCount
.
get
Pagination
ValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
result
.
put
(((
ParameterMarkerLimitValueSegment
)
rowCount
.
get
Limit
ValueSegment
()).
getParameterIndex
(),
getRewriteRowCount
(
isFetchAll
,
databaseType
));
result
.
put
(((
ParameterMarkerLimitValueSegment
)
rowCount
.
get
Pagination
ValueSegment
()).
getParameterIndex
(),
getRewriteRowCount
(
isFetchAll
,
databaseType
));
}
}
return
result
;
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;
...
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.core.route.limit;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
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.
* Limit value.
...
@@ -30,7 +30,7 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegm
...
@@ -30,7 +30,7 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegm
@Getter
@Getter
public
final
class
LimitValue
{
public
final
class
LimitValue
{
private
final
LimitValueSegment
limit
ValueSegment
;
private
final
PaginationValueSegment
pagination
ValueSegment
;
private
final
int
value
;
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 {
...
@@ -103,8 +103,8 @@ public final class ParsingSQLRouter implements ShardingRouter {
mergeShardingValues
(
optimizeResult
.
getShardingConditions
());
mergeShardingValues
(
optimizeResult
.
getShardingConditions
());
}
}
RoutingResult
routingResult
=
RoutingEngineFactory
.
newInstance
(
shardingRule
,
shardingMetaData
.
getDataSource
(),
sqlStatement
,
optimizeResult
).
route
();
RoutingResult
routingResult
=
RoutingEngineFactory
.
newInstance
(
shardingRule
,
shardingMetaData
.
getDataSource
(),
sqlStatement
,
optimizeResult
).
route
();
if
(
sqlStatement
instanceof
SelectStatement
&&
null
!=
((
SelectStatement
)
sqlStatement
).
get
Limit
()
&&
!
routingResult
.
isSingleRouting
())
{
if
(
sqlStatement
instanceof
SelectStatement
&&
null
!=
((
SelectStatement
)
sqlStatement
).
get
Pagination
()
&&
!
routingResult
.
isSingleRouting
())
{
result
.
setLimit
(
new
Limit
(((
SelectStatement
)
sqlStatement
).
get
Limit
(),
parameters
));
result
.
setLimit
(
new
Limit
(((
SelectStatement
)
sqlStatement
).
get
Pagination
(),
parameters
));
}
}
if
(
needMerge
)
{
if
(
needMerge
)
{
Preconditions
.
checkState
(
1
==
routingResult
.
getRoutingUnits
().
size
(),
"Must have one sharding with subquery."
);
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;
...
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.core.constant.DatabaseType;
import
org.apache.shardingsphere.core.metadata.ShardingMetaData
;
import
org.apache.shardingsphere.core.metadata.ShardingMetaData
;
import
org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData
;
import
org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData
;
import
org.apache.shardingsphere.core.parse.cache.ParsingResultCache
;
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.parse.sql.statement.dml.SelectStatement
;
import
org.apache.shardingsphere.core.route.fixture.HintShardingAlgorithmFixture
;
import
org.apache.shardingsphere.core.route.fixture.HintShardingAlgorithmFixture
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
import
org.apache.shardingsphere.core.rule.ShardingRule
;
...
@@ -89,17 +89,17 @@ public final class DatabaseTest {
...
@@ -89,17 +89,17 @@ public final class DatabaseTest {
String
originSQL
=
"select user_id from tbl_pagination limit 0,5"
;
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
);
SQLRouteResult
actual
=
new
StatementRoutingEngine
(
shardingRule
,
mock
(
ShardingMetaData
.
class
),
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
originSQL
);
SelectStatement
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
SelectStatement
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
assertTrue
(
selectStatement
.
get
Limit
().
getOffset
().
isPresent
());
assertTrue
(
selectStatement
.
get
Pagination
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getOffset
().
get
()).
getValue
(),
is
(
0
));
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getOffset
().
get
()).
getValue
(),
is
(
0
));
assertTrue
(
selectStatement
.
get
Limit
().
getRowCount
().
isPresent
());
assertTrue
(
selectStatement
.
get
Pagination
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getRowCount
().
get
()).
getValue
(),
is
(
5
));
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getRowCount
().
get
()).
getValue
(),
is
(
5
));
originSQL
=
"select user_id from tbl_pagination limit 5,5"
;
originSQL
=
"select user_id from tbl_pagination limit 5,5"
;
actual
=
new
StatementRoutingEngine
(
shardingRule
,
mock
(
ShardingMetaData
.
class
),
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
originSQL
);
actual
=
new
StatementRoutingEngine
(
shardingRule
,
mock
(
ShardingMetaData
.
class
),
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
originSQL
);
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
assertTrue
(
selectStatement
.
get
Limit
().
getOffset
().
isPresent
());
assertTrue
(
selectStatement
.
get
Pagination
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Limit
().
getRowCount
().
isPresent
());
assertTrue
(
selectStatement
.
get
Pagination
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getRowCount
().
get
()).
getValue
(),
is
(
5
));
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getRowCount
().
get
()).
getValue
(),
is
(
5
));
}
}
@Test
@Test
...
@@ -119,18 +119,18 @@ public final class DatabaseTest {
...
@@ -119,18 +119,18 @@ public final class DatabaseTest {
when
(
shardingMetaData
.
getTable
()).
thenReturn
(
mock
(
ShardingTableMetaData
.
class
));
when
(
shardingMetaData
.
getTable
()).
thenReturn
(
mock
(
ShardingTableMetaData
.
class
));
SQLRouteResult
actual
=
new
PreparedStatementRoutingEngine
(
originSQL
,
rule
,
shardingMetaData
,
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
Lists
.<
Object
>
newArrayList
(
13
,
173
));
SQLRouteResult
actual
=
new
PreparedStatementRoutingEngine
(
originSQL
,
rule
,
shardingMetaData
,
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
Lists
.<
Object
>
newArrayList
(
13
,
173
));
SelectStatement
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
SelectStatement
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
assertTrue
(
selectStatement
.
get
Limit
().
getOffset
().
isPresent
());
assertTrue
(
selectStatement
.
get
Pagination
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Limit
().
getRowCount
().
isPresent
());
assertTrue
(
selectStatement
.
get
Pagination
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getRowCount
().
get
()).
getValue
(),
is
(
10
));
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getRowCount
().
get
()).
getValue
(),
is
(
10
));
assertThat
(
actual
.
getRoutingResult
().
getRoutingUnits
().
size
(),
is
(
1
));
assertThat
(
actual
.
getRoutingResult
().
getRoutingUnits
().
size
(),
is
(
1
));
originSQL
=
"select city_id from t_user where city_id in (?,?) limit 5,10"
;
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
));
actual
=
new
PreparedStatementRoutingEngine
(
originSQL
,
rule
,
shardingMetaData
,
DatabaseType
.
MySQL
,
new
ParsingResultCache
()).
route
(
Lists
.<
Object
>
newArrayList
(
89
,
84
));
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
selectStatement
=
(
SelectStatement
)
actual
.
getSqlStatement
();
assertTrue
(
selectStatement
.
get
Limit
().
getOffset
().
isPresent
());
assertTrue
(
selectStatement
.
get
Pagination
().
getOffset
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getOffset
().
get
()).
getValue
(),
is
(
5
));
assertTrue
(
selectStatement
.
get
Limit
().
getRowCount
().
isPresent
());
assertTrue
(
selectStatement
.
get
Pagination
().
getRowCount
().
isPresent
());
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Limit
().
getRowCount
().
get
()).
getValue
(),
is
(
10
));
assertThat
(((
NumberLiteralLimitValueSegment
)
selectStatement
.
get
Pagination
().
getRowCount
().
get
()).
getValue
(),
is
(
10
));
assertThat
(
actual
.
getRoutingResult
().
getRoutingUnits
().
size
(),
is
(
2
));
assertThat
(
actual
.
getRoutingResult
().
getRoutingUnits
().
size
(),
is
(
2
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录