diff --git a/sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResult.java b/sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResult.java index 4b84d50c5ca88d3963259db361c10c418b35124b..d43bed48e43b0a691747645c371dec993dde0312 100644 --- a/sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResult.java +++ b/sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResult.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.core.route.limit.Limit; import java.sql.SQLException; /** - * Decorator merged result for rownum pagination. + * Decorator merged result for row number pagination. * * @author zhangliang */ @@ -47,7 +47,7 @@ public final class RowNumberDecoratorMergedResult extends DecoratorMergedResult if (null == limit.getOffset()) { end = 0; } else { - end = limit.getOffset().getLimitValueSegment().isBoundOpened() ? limit.getOffsetValue() - 1 : limit.getOffsetValue(); + end = limit.getOffset().getPaginationValueSegment().isBoundOpened() ? limit.getOffsetValue() - 1 : limit.getOffsetValue(); } for (int i = 0; i < end; i++) { if (!getMergedResult().next()) { @@ -66,7 +66,7 @@ public final class RowNumberDecoratorMergedResult extends DecoratorMergedResult if (limit.getRowCountValue() < 0) { return getMergedResult().next(); } - if (limit.getRowCount().getLimitValueSegment().isBoundOpened()) { + if (limit.getRowCount().getPaginationValueSegment().isBoundOpened()) { return rowNumber++ <= limit.getRowCountValue() && getMergedResult().next(); } return rowNumber++ < limit.getRowCountValue() && getMergedResult().next(); diff --git a/sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResult.java b/sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResult.java index 020cd333245db97d7c0c5dd7981be213b8aa1242..733d3b50c53fac4a3ddf2fe0411f45f046cf9957 100644 --- a/sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResult.java +++ b/sharding-core/sharding-core-merge/src/main/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResult.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.core.route.limit.Limit; import java.sql.SQLException; /** - * Decorator merged result for top and rownum pagination. + * Decorator merged result for top and row number pagination. * * @author zhangliang */ @@ -47,7 +47,7 @@ public final class TopAndRowNumberDecoratorMergedResult extends DecoratorMergedR if (null == limit.getOffset()) { end = 0; } else { - end = limit.getOffset().getLimitValueSegment().isBoundOpened() ? limit.getOffsetValue() - 1 : limit.getOffsetValue(); + end = limit.getOffset().getPaginationValueSegment().isBoundOpened() ? limit.getOffsetValue() - 1 : limit.getOffsetValue(); } for (int i = 0; i < end; i++) { if (!getMergedResult().next()) { diff --git a/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/DQLMergeEngineTest.java b/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/DQLMergeEngineTest.java index e7119c12a390623ad9246dc7b8c755ecbf8e4b5a..01ca3e4d024645926017fcb3834ac871119b65b5 100644 --- a/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/DQLMergeEngineTest.java +++ b/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/DQLMergeEngineTest.java @@ -33,8 +33,8 @@ import org.apache.shardingsphere.core.merge.dql.pagination.RowNumberDecoratorMer import org.apache.shardingsphere.core.merge.dql.pagination.TopAndRowNumberDecoratorMergedResult; import org.apache.shardingsphere.core.merge.fixture.TestQueryResult; import org.apache.shardingsphere.core.parse.sql.context.selectitem.AggregationSelectItem; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; import org.apache.shardingsphere.core.route.SQLRouteResult; import org.apache.shardingsphere.core.route.limit.Limit; @@ -91,14 +91,14 @@ public final class DQLMergeEngineTest { @Test public void assertBuildIteratorStreamMergedResultWithLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.MySQL, routeResult, singleQueryResult); assertThat(mergeEngine.merge(), instanceOf(IteratorStreamMergedResult.class)); } @Test public void assertBuildIteratorStreamMergedResultWithMySQLLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.MySQL, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertThat(actual, instanceOf(LimitDecoratorMergedResult.class)); @@ -107,7 +107,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildIteratorStreamMergedResultWithOracleLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.Oracle, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class)); @@ -116,7 +116,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildIteratorStreamMergedResultWithSQLServerLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class)); @@ -132,7 +132,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildOrderByStreamMergedResultWithMySQLLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getOrderByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); mergeEngine = new DQLMergeEngine(DatabaseType.MySQL, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); @@ -142,7 +142,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildOrderByStreamMergedResultWithOracleLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getOrderByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); mergeEngine = new DQLMergeEngine(DatabaseType.Oracle, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); @@ -152,7 +152,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildOrderByStreamMergedResultWithSQLServerLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getOrderByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); @@ -170,7 +170,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildGroupByStreamMergedResultWithMySQLLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getGroupByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); selectStatement.getOrderByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); mergeEngine = new DQLMergeEngine(DatabaseType.MySQL, routeResult, queryResults); @@ -181,7 +181,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildGroupByStreamMergedResultWithOracleLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getGroupByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); selectStatement.getOrderByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); mergeEngine = new DQLMergeEngine(DatabaseType.Oracle, routeResult, queryResults); @@ -192,7 +192,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildGroupByStreamMergedResultWithSQLServerLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getGroupByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); selectStatement.getOrderByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); @@ -210,7 +210,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildGroupByMemoryMergedResultWithMySQLLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getGroupByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); mergeEngine = new DQLMergeEngine(DatabaseType.MySQL, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); @@ -220,7 +220,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildGroupByMemoryMergedResultWithOracleLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getGroupByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); selectStatement.getOrderByItems().add(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC)); mergeEngine = new DQLMergeEngine(DatabaseType.Oracle, routeResult, queryResults); @@ -231,7 +231,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildGroupByMemoryMergedResultWithSQLServerLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getGroupByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)); selectStatement.getGroupByItems().add(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); @@ -249,7 +249,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithMySQLLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getItems().add(new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.absent())); mergeEngine = new DQLMergeEngine(DatabaseType.MySQL, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); @@ -259,7 +259,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getItems().add(new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.absent())); mergeEngine = new DQLMergeEngine(DatabaseType.Oracle, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); @@ -269,7 +269,7 @@ public final class DQLMergeEngineTest { @Test public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithSQLServerLimit() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); selectStatement.getItems().add(new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.absent())); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); diff --git a/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/LimitDecoratorMergedResultTest.java b/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/LimitDecoratorMergedResultTest.java index 5a9f462eea61d09d8f1b8f899787b86c6279c142..6127eb7905fa631663393b11ef9535d4a483072a 100644 --- a/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/LimitDecoratorMergedResultTest.java +++ b/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/LimitDecoratorMergedResultTest.java @@ -23,8 +23,8 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult; import org.apache.shardingsphere.core.merge.MergedResult; import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine; import org.apache.shardingsphere.core.merge.fixture.TestQueryResult; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; import org.apache.shardingsphere.core.route.SQLRouteResult; import org.apache.shardingsphere.core.route.limit.Limit; @@ -66,12 +66,12 @@ public final class LimitDecoratorMergedResultTest { } SelectStatement selectStatement = new SelectStatement(); routeResult = new SQLRouteResult(selectStatement); - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); } @Test public void assertNextForSkipAll() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, Integer.MAX_VALUE, true), null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, Integer.MAX_VALUE), null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.MySQL, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertFalse(actual.next()); @@ -79,7 +79,7 @@ public final class LimitDecoratorMergedResultTest { @Test public void assertNextWithoutRowCount() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2, true), null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2), null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.MySQL, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); for (int i = 0; i < 6; i++) { @@ -90,7 +90,7 @@ public final class LimitDecoratorMergedResultTest { @Test public void assertNextWithRowCount() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2, true), new NumberLiteralLimitValueSegment(0, 0, 2, false)), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2), new NumberLiteralLimitValueSegment(0, 0, 2)), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.MySQL, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertTrue(actual.next()); diff --git a/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java b/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java index 6f5cb0637420d65e4fc8e16511f06621f2b27e19..1caf5286015cdf8a0a33f713c4bab353b4faad80 100644 --- a/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java +++ b/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/RowNumberDecoratorMergedResultTest.java @@ -23,8 +23,8 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult; import org.apache.shardingsphere.core.merge.MergedResult; import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine; import org.apache.shardingsphere.core.merge.fixture.TestQueryResult; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment; import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; import org.apache.shardingsphere.core.route.SQLRouteResult; import org.apache.shardingsphere.core.route.limit.Limit; @@ -69,7 +69,7 @@ public final class RowNumberDecoratorMergedResultTest { @Test public void assertNextForSkipAll() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, Integer.MAX_VALUE, true), null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, Integer.MAX_VALUE, true), null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.Oracle, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertFalse(actual.next()); @@ -77,7 +77,7 @@ public final class RowNumberDecoratorMergedResultTest { @Test public void assertNextWithoutOffsetWithoutRowCount() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.Oracle, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); for (int i = 0; i < 8; i++) { @@ -88,7 +88,8 @@ public final class RowNumberDecoratorMergedResultTest { @Test public void assertNextForRowCountBoundOpenedFalse() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2, true), new NumberLiteralLimitValueSegment(0, 0, 4, false)), Collections.emptyList())); + routeResult.setLimit(new Limit( + new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, true), new NumberLiteralRowNumberValueSegment(0, 0, 4, false)), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.Oracle, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertTrue(actual.next()); @@ -98,7 +99,8 @@ public final class RowNumberDecoratorMergedResultTest { @Test public void assertNextForRowCountBoundOpenedTrue() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2, true), new NumberLiteralLimitValueSegment(0, 0, 4, true)), Collections.emptyList())); + routeResult.setLimit(new Limit( + new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, true), new NumberLiteralRowNumberValueSegment(0, 0, 4, true)), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.Oracle, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertTrue(actual.next()); diff --git a/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java b/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java index 0546286d9038d769377e2d39ed00f5637e6ec69b..077f9b38e191d071b891b89ac532203bba4a643a 100644 --- a/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java +++ b/sharding-core/sharding-core-merge/src/test/java/org/apache/shardingsphere/core/merge/dql/pagination/TopAndRowNumberDecoratorMergedResultTest.java @@ -23,8 +23,9 @@ import org.apache.shardingsphere.core.execute.sql.execute.result.QueryResult; import org.apache.shardingsphere.core.merge.MergedResult; import org.apache.shardingsphere.core.merge.dql.DQLMergeEngine; import org.apache.shardingsphere.core.merge.fixture.TestQueryResult; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment; import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; import org.apache.shardingsphere.core.route.SQLRouteResult; import org.apache.shardingsphere.core.route.limit.Limit; @@ -49,8 +50,6 @@ public final class TopAndRowNumberDecoratorMergedResultTest { private List queryResults; - private SelectStatement selectStatement; - private SQLRouteResult routeResult; @Before @@ -66,13 +65,12 @@ public final class TopAndRowNumberDecoratorMergedResultTest { for (ResultSet each : resultSets) { queryResults.add(new TestQueryResult(each)); } - selectStatement = new SelectStatement(); - routeResult = new SQLRouteResult(selectStatement); + routeResult = new SQLRouteResult(new SelectStatement()); } @Test public void assertNextForSkipAll() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, Integer.MAX_VALUE, true), null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, Integer.MAX_VALUE, true), null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertFalse(actual.next()); @@ -80,7 +78,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest { @Test public void assertNextWithoutOffsetWithRowCount() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, null, new NumberLiteralLimitValueSegment(0, 0, 5, false)), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, null, new NumberLiteralLimitValueSegment(0, 0, 5)), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); for (int i = 0; i < 5; i++) { @@ -91,7 +89,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest { @Test public void assertNextWithOffsetWithoutRowCount() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2, true), null), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, true), null), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); for (int i = 0; i < 7; i++) { @@ -102,7 +100,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest { @Test public void assertNextWithOffsetBoundOpenedFalse() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2, false), new NumberLiteralLimitValueSegment(0, 0, 4, false)), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, false), new NumberLiteralLimitValueSegment(0, 0, 4)), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertTrue(actual.next()); @@ -112,7 +110,7 @@ public final class TopAndRowNumberDecoratorMergedResultTest { @Test public void assertNextWithOffsetBoundOpenedTrue() throws SQLException { - routeResult.setLimit(new Limit(new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(0, 0, 2, true), new NumberLiteralLimitValueSegment(0, 0, 4, false)), Collections.emptyList())); + routeResult.setLimit(new Limit(new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(0, 0, 2, true), new NumberLiteralLimitValueSegment(0, 0, 4)), Collections.emptyList())); mergeEngine = new DQLMergeEngine(DatabaseType.SQLServer, routeResult, queryResults); MergedResult actual = mergeEngine.merge(); assertTrue(actual.next()); diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/extractor/impl/dml/select/LimitExtractor.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/extractor/impl/dml/select/LimitExtractor.java index 95d26b2d8fc5d6d71d2846120b3651a8275a75bb..52b4891d4bff2139881c754e3258cca49f49c451 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/extractor/impl/dml/select/LimitExtractor.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/extractor/impl/dml/select/LimitExtractor.java @@ -25,10 +25,10 @@ import org.apache.shardingsphere.core.parse.extractor.impl.common.expression.imp import org.apache.shardingsphere.core.parse.extractor.util.ExtractorUtils; import org.apache.shardingsphere.core.parse.extractor.util.RuleName; import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.ParameterMarkerLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.LimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.ParameterMarkerLimitValueSegment; import org.apache.shardingsphere.core.util.NumberUtil; import java.util.Map; @@ -45,11 +45,11 @@ public final class LimitExtractor implements OptionalSQLSegmentExtractor { private final ParameterMarkerExpressionExtractor parameterMarkerExpressionExtractor = new ParameterMarkerExpressionExtractor(); @Override - public Optional extract(final ParserRuleContext ancestorNode, final Map parameterMarkerIndexes) { + public Optional extract(final ParserRuleContext ancestorNode, final Map parameterMarkerIndexes) { Optional limitNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.LIMIT_CLAUSE); return limitNode.isPresent() - ? Optional.of(new LimitSegment(limitNode.get().getStart().getStartIndex(), limitNode.get().getStop().getStopIndex(), - extractOffset(limitNode.get(), parameterMarkerIndexes).orNull(), extractRowCount(limitNode.get(), parameterMarkerIndexes).orNull())) : Optional.absent(); + ? Optional.of(new PaginationSegment(limitNode.get().getStart().getStartIndex(), limitNode.get().getStop().getStopIndex(), + extractOffset(limitNode.get(), parameterMarkerIndexes).orNull(), extractRowCount(limitNode.get(), parameterMarkerIndexes).orNull())) : Optional.absent(); } private Optional extractOffset(final ParserRuleContext limitNode, final Map parameterMarkerIndexes) { @@ -66,11 +66,11 @@ public final class LimitExtractor implements OptionalSQLSegmentExtractor { Optional parameterMarkerExpression = parameterMarkerExpressionExtractor.extract(limitValueNode, parameterMarkerIndexes); if (parameterMarkerExpression.isPresent()) { return new ParameterMarkerLimitValueSegment( - limitValueNode.getStart().getStartIndex(), limitValueNode.getStop().getStopIndex(), parameterMarkerExpression.get().getParameterMarkerIndex(), false); + limitValueNode.getStart().getStartIndex(), limitValueNode.getStop().getStopIndex(), parameterMarkerExpression.get().getParameterMarkerIndex()); } Optional numberLiteralsNode = ExtractorUtils.findFirstChildNode(limitValueNode, RuleName.NUMBER_LITERALS); Preconditions.checkState(numberLiteralsNode.isPresent()); return new NumberLiteralLimitValueSegment( - limitValueNode.getStart().getStartIndex(), limitValueNode.getStop().getStopIndex(), NumberUtil.getExactlyNumber(numberLiteralsNode.get().getText(), 10).intValue(), false); + limitValueNode.getStart().getStartIndex(), limitValueNode.getStop().getStopIndex(), NumberUtil.getExactlyNumber(numberLiteralsNode.get().getText(), 10).intValue()); } } diff --git a/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 b/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 index faf3187897a3e92ef135175ae457b31be0b90c13..02fa415d2f1a7a5c689a83c1ed2f22bfea224e8d 100644 --- a/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 +++ b/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 @@ -27,10 +27,10 @@ import org.apache.shardingsphere.core.parse.extractor.util.RuleName; import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.ParameterMarkerLimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.TopSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.LimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.ParameterMarkerLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.top.TopSegment; import java.util.Map; @@ -62,11 +62,11 @@ public final class TopSelectItemExtractor implements OptionalSQLSegmentExtractor private Optional createLimitValueSegment(final ExpressionSegment topExpr) { if (topExpr instanceof ParameterMarkerExpressionSegment) { return Optional.of( - new ParameterMarkerLimitValueSegment(topExpr.getStartIndex(), topExpr.getStopIndex(), ((ParameterMarkerExpressionSegment) topExpr).getParameterMarkerIndex(), false)); + new ParameterMarkerLimitValueSegment(topExpr.getStartIndex(), topExpr.getStopIndex(), ((ParameterMarkerExpressionSegment) topExpr).getParameterMarkerIndex())); } if (topExpr instanceof LiteralExpressionSegment && ((LiteralExpressionSegment) topExpr).getLiterals() instanceof Number) { return Optional.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(); } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/LimitFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/LimitFiller.java index a78021c5934a2f5e79da7c713fb8d6c4a04404fa..3169046161a0f38ec72f90e915a249638ea8fe33 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/LimitFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/LimitFiller.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.core.parse.filler.common.dml; import org.apache.shardingsphere.core.parse.filler.api.SQLSegmentFiller; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement; import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; @@ -27,10 +27,10 @@ import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; * * @author duhongjun */ -public final class LimitFiller implements SQLSegmentFiller { +public final class LimitFiller implements SQLSegmentFiller { @Override - public void fill(final LimitSegment sqlSegment, final SQLStatement sqlStatement) { - ((SelectStatement) sqlStatement).setLimit(sqlSegment); + public void fill(final PaginationSegment sqlSegment, final SQLStatement sqlStatement) { + ((SelectStatement) sqlStatement).setPagination(sqlSegment); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/SelectItemFiller.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/SelectItemFiller.java index 6ca6d17917e1c4c267312a423cb6bcd7ab5f1be8..33e7441a033075d66576a0da132cd146c0bb3717 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/SelectItemFiller.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/filler/common/dml/SelectItemFiller.java @@ -32,8 +32,8 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.item.ColumnSelectIte import org.apache.shardingsphere.core.parse.sql.segment.dml.item.ExpressionSelectItemSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.item.ShorthandSelectItemSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.TopSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.top.TopSegment; import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement; import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; @@ -109,7 +109,7 @@ public final class SelectItemFiller implements SQLSegmentFiller rowNumberPredicates) { - LimitValueSegment rowCount = null; - LimitValueSegment offset = null; + RowNumberValueSegment rowCount = null; + RowNumberValueSegment offset = null; for (PredicateSegment each : rowNumberPredicates) { ExpressionSegment expression = ((PredicateCompareRightValue) each.getRightValue()).getExpression(); switch (((PredicateCompareRightValue) each.getRightValue()).getOperator()) { case ">": - offset = createLimitValueSegment(expression, false); + offset = createRowNumberValueSegment(expression, false); break; case ">=": - offset = createLimitValueSegment(expression, true); + offset = createRowNumberValueSegment(expression, true); break; case "<": - rowCount = createLimitValueSegment(expression, false); + rowCount = createRowNumberValueSegment(expression, false); break; case "<=": - rowCount = createLimitValueSegment(expression, true); + rowCount = createRowNumberValueSegment(expression, true); break; default: break; } } - selectStatement.setLimit(new LimitSegment(-1, -1, offset, rowCount)); + selectStatement.setPagination(new PaginationSegment(-1, -1, offset, rowCount)); } - private LimitValueSegment createLimitValueSegment(final ExpressionSegment expression, final boolean boundOpened) { - if (expression instanceof LiteralExpressionSegment) { - return new NumberLiteralLimitValueSegment(expression.getStartIndex(), expression.getStopIndex(), (Integer) ((LiteralExpressionSegment) expression).getLiterals(), boundOpened); - } - return new ParameterMarkerLimitValueSegment(expression.getStartIndex(), expression.getStopIndex(), ((ParameterMarkerExpressionSegment) expression).getParameterMarkerIndex(), boundOpened); + private RowNumberValueSegment createRowNumberValueSegment(final ExpressionSegment expression, final boolean boundOpened) { + return expression instanceof LiteralExpressionSegment + ? new NumberLiteralRowNumberValueSegment(expression.getStartIndex(), expression.getStopIndex(), (int) ((LiteralExpressionSegment) expression).getLiterals(), boundOpened) + : new ParameterMarkerRowNumberValueSegment( + expression.getStartIndex(), expression.getStopIndex(), ((ParameterMarkerExpressionSegment) expression).getParameterMarkerIndex(), boundOpened); } } diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/NumberLiteralPaginationValueSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/NumberLiteralPaginationValueSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..f0309af7dbb323912ad852b45085d9a6cdd71908 --- /dev/null +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/NumberLiteralPaginationValueSegment.java @@ -0,0 +1,35 @@ +/* + * 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(); +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..2bb40fa2f1394025eb3f2b9477590b75a4c05e03 --- /dev/null +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationSegment.java @@ -0,0 +1,59 @@ +/* + * 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 getOffset() { + return Optional.fromNullable(offset); + } + + /** + * Get row count. + * + * @return row count + */ + public Optional getRowCount() { + return Optional.fromNullable(rowCount); + } +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationValueSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationValueSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..a4a3925d67ffa299608c351c1b8734aa1bfd4d04 --- /dev/null +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/PaginationValueSegment.java @@ -0,0 +1,39 @@ +/* + * 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; +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/ParameterMarkerPaginationValueSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/ParameterMarkerPaginationValueSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..703921a4815a32b489c3cb1abbad502b8db183a0 --- /dev/null +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/ParameterMarkerPaginationValueSegment.java @@ -0,0 +1,35 @@ +/* + * 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(); +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/LimitValueSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/LimitValueSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..54cd80599438be52815ce183af3f774cfcb4cb3d --- /dev/null +++ b/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,0 +1,33 @@ +/* + * 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); + } +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/NumberLiteralLimitValueSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/NumberLiteralLimitValueSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..160014970749c9e7894d790e23fbfb2687940038 --- /dev/null +++ b/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,0 +1,37 @@ +/* + * 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; + } +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/ParameterMarkerLimitValueSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/limit/ParameterMarkerLimitValueSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..08cb25149de8cc07b1016de19c3a7e821f2ade6b --- /dev/null +++ b/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,0 +1,37 @@ +/* + * 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; + } +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/NumberLiteralRowNumberValueSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/NumberLiteralRowNumberValueSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..7ebf15dbaa4a2ad8ea539256db21b95341c4f744 --- /dev/null +++ b/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,0 +1,37 @@ +/* + * 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; + } +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/ParameterMarkerRowNumberValueSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/ParameterMarkerRowNumberValueSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..5d0b1bdec7a009eb7a5067a1a581611ece23666f --- /dev/null +++ b/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,0 +1,37 @@ +/* + * 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; + } +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/RowNumberValueSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/rownum/RowNumberValueSegment.java new file mode 100644 index 0000000000000000000000000000000000000000..6c3f59c82ce1a3e1dff50d8cae92b387825fa69a --- /dev/null +++ b/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,0 +1,32 @@ +/* + * 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); + } +} diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/limit/TopSegment.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/top/TopSegment.java similarity index 88% rename from sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/limit/TopSegment.java rename to sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/top/TopSegment.java index 8f7b248088840cf8419c8b124f208bb03d11a30f..2bd14451584eda831a753a156d71bf3aa7e07c3d 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/limit/TopSegment.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/segment/dml/pagination/top/TopSegment.java @@ -15,11 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.core.parse.sql.segment.dml.limit; +package org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.top; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.core.parse.sql.segment.dml.item.SelectItemSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.LimitValueSegment; /** * Top segment. diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/dml/SelectStatement.java b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/dml/SelectStatement.java index d60dfcb8cfaa84c65c9418f543b4604e57c07165..a4544b193dcace0adb94d983dc6b81acbd4392f4 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/dml/SelectStatement.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/java/org/apache/shardingsphere/core/parse/sql/statement/dml/SelectStatement.java @@ -29,12 +29,12 @@ import org.apache.shardingsphere.core.parse.sql.context.selectitem.DistinctSelec import org.apache.shardingsphere.core.parse.sql.context.selectitem.SelectItem; import org.apache.shardingsphere.core.parse.sql.context.selectitem.StarSelectItem; import org.apache.shardingsphere.core.parse.sql.context.table.Table; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ColumnOrderByItemSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ExpressionOrderByItemSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.IndexOrderByItemSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.OrderByItemSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.TextOrderByItemSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; import org.apache.shardingsphere.core.parse.util.SQLUtil; import java.util.Collection; @@ -71,7 +71,7 @@ public final class SelectStatement extends DQLStatement { private int groupByLastIndex; - private LimitSegment limit; + private PaginationSegment pagination; private SelectStatement parentStatement; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/filler-rule-definition.xml b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/filler-rule-definition.xml index ab4d88791b3d093997a22c19f2cdb1186628224d..3f955f2ddc977d41de96262d17845a7eadc642d9 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/filler-rule-definition.xml +++ b/sharding-core/sharding-core-parse/sharding-core-parse-common/src/main/resources/META-INF/parsing-rule-definition/filler-rule-definition.xml @@ -29,7 +29,7 @@ - + diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/SQLStatementAssert.java b/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/SQLStatementAssert.java index a8cd06834d41b1f4274df1ffb9882bf108e8a4f2..f8caa72b0b0d5b9505ff11e926487fac75fbfcd9 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/SQLStatementAssert.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/SQLStatementAssert.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.core.parse.integrate.asserts.condition.Conditio import org.apache.shardingsphere.core.parse.integrate.asserts.groupby.GroupByAssert; import org.apache.shardingsphere.core.parse.integrate.asserts.index.IndexAssert; import org.apache.shardingsphere.core.parse.integrate.asserts.item.ItemAssert; -import org.apache.shardingsphere.core.parse.integrate.asserts.limit.LimitAssert; +import org.apache.shardingsphere.core.parse.integrate.asserts.limit.PaginationAssert; import org.apache.shardingsphere.core.parse.integrate.asserts.meta.TableMetaDataAssert; import org.apache.shardingsphere.core.parse.integrate.asserts.orderby.OrderByAssert; import org.apache.shardingsphere.core.parse.integrate.asserts.table.AlterTableAssert; @@ -61,7 +61,7 @@ public final class SQLStatementAssert { private final OrderByAssert orderByAssert; - private final LimitAssert limitAssert; + private final PaginationAssert paginationAssert; private final TableMetaDataAssert metaAssert; @@ -84,7 +84,7 @@ public final class SQLStatementAssert { itemAssert = new ItemAssert(assertMessage); groupByAssert = new GroupByAssert(assertMessage); orderByAssert = new OrderByAssert(assertMessage); - limitAssert = new LimitAssert(sqlCaseType, assertMessage); + paginationAssert = new PaginationAssert(sqlCaseType, assertMessage); metaAssert = new TableMetaDataAssert(assertMessage); alterTableAssert = new AlterTableAssert(assertMessage); this.databaseType = databaseType; @@ -118,7 +118,7 @@ public final class SQLStatementAssert { itemAssert.assertItems(actual.getItems(), expected.getSelectItems()); groupByAssert.assertGroupByItems(actual.getGroupByItems(), expected.getGroupByColumns()); orderByAssert.assertOrderByItems(actual.getOrderByItems(), expected.getOrderByColumns()); - limitAssert.assertLimit(actual.getLimit(), expected.getLimit()); + paginationAssert.assertPagination(actual.getPagination(), expected.getLimit()); } private void assertCreateTableStatement(final CreateTableStatement actual) { diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/limit/LimitAssert.java b/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/limit/PaginationAssert.java similarity index 52% rename from sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/limit/LimitAssert.java rename to sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/limit/PaginationAssert.java index 013843b3898e605f7866c71eeec673773c679822..5b3093a70228fff70197da03df51bad09e44503e 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/limit/LimitAssert.java +++ b/sharding-core/sharding-core-parse/sharding-core-parse-test/src/test/java/org/apache/shardingsphere/core/parse/integrate/asserts/limit/PaginationAssert.java @@ -20,9 +20,9 @@ package org.apache.shardingsphere.core.parse.integrate.asserts.limit; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.core.parse.integrate.asserts.SQLStatementAssertMessage; import org.apache.shardingsphere.core.parse.integrate.jaxb.limit.ExpectedLimit; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.ParameterMarkerLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.ParameterMarkerPaginationValueSegment; import org.apache.shardingsphere.test.sql.SQLCaseType; import static org.hamcrest.CoreMatchers.is; @@ -30,45 +30,45 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; /** - * Limit assert. + * Pagination assert. * * @author zhangliang */ @RequiredArgsConstructor -public final class LimitAssert { +public final class PaginationAssert { private final SQLCaseType sqlCaseType; private final SQLStatementAssertMessage assertMessage; /** - * Assert limit. + * Assert pagination. * - * @param actual actual limit - * @param expected expected limit + * @param actual actual pagination + * @param expected expected pagination */ - public void assertLimit(final LimitSegment actual, final ExpectedLimit expected) { + public void assertPagination(final PaginationSegment actual, final ExpectedLimit expected) { if (null == actual) { - assertNull(assertMessage.getFullAssertMessage("Limit should not exist: "), expected); + assertNull(assertMessage.getFullAssertMessage("Pagination should not exist: "), expected); return; } if (SQLCaseType.Placeholder == sqlCaseType) { if (actual.getOffset().isPresent()) { - assertThat(assertMessage.getFullAssertMessage("Limit offset index assertion error: "), - ((ParameterMarkerLimitValueSegment) actual.getOffset().get()).getParameterIndex(), is(expected.getOffsetParameterIndex())); + assertThat(assertMessage.getFullAssertMessage("Pagination offset index assertion error: "), + ((ParameterMarkerPaginationValueSegment) actual.getOffset().get()).getParameterIndex(), is(expected.getOffsetParameterIndex())); } if (actual.getRowCount().isPresent()) { - assertThat(assertMessage.getFullAssertMessage("Limit row count index assertion error: "), - ((ParameterMarkerLimitValueSegment) actual.getRowCount().get()).getParameterIndex(), is(expected.getRowCountParameterIndex())); + assertThat(assertMessage.getFullAssertMessage("Pagination row count index assertion error: "), + ((ParameterMarkerPaginationValueSegment) actual.getRowCount().get()).getParameterIndex(), is(expected.getRowCountParameterIndex())); } } else { if (actual.getOffset().isPresent()) { - assertThat(assertMessage.getFullAssertMessage("Limit offset value assertion error: "), - ((NumberLiteralLimitValueSegment) actual.getOffset().get()).getValue(), is(expected.getOffset())); + assertThat(assertMessage.getFullAssertMessage("Pagination offset value assertion error: "), + ((NumberLiteralPaginationValueSegment) actual.getOffset().get()).getValue(), is(expected.getOffset())); } if (actual.getRowCount().isPresent()) { - assertThat(assertMessage.getFullAssertMessage("Limit row count value assertion error: "), - ((NumberLiteralLimitValueSegment) actual.getRowCount().get()).getValue(), is(expected.getRowCount())); + assertThat(assertMessage.getFullAssertMessage("Pagination row count value assertion error: "), + ((NumberLiteralPaginationValueSegment) actual.getRowCount().get()).getValue(), is(expected.getRowCount())); } } } diff --git a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/OffsetTokenGenerator.java b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/OffsetTokenGenerator.java index 05afdb8e64ee0af20de00cdcd97e3cd98ea30b49..c6e7de301a4ff87468836f5850731048048c2120 100644 --- a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/OffsetTokenGenerator.java +++ b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/OffsetTokenGenerator.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.core.rewrite.token.generator; import com.google.common.base.Optional; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment; import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement; import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; import org.apache.shardingsphere.core.rewrite.token.pojo.OffsetToken; @@ -37,17 +37,18 @@ public final class OffsetTokenGenerator implements OptionalSQLTokenGenerator offsetSegment = getLiteralOffsetSegment((SelectStatement) sqlStatement); + Optional offsetSegment = getLiteralOffsetSegment((SelectStatement) sqlStatement); return offsetSegment.isPresent() - ? Optional.of(new OffsetToken(offsetSegment.get().getStartIndex(), offsetSegment.get().getStopIndex(), ((NumberLiteralLimitValueSegment) offsetSegment.get()).getValue())) + ? Optional.of(new OffsetToken(offsetSegment.get().getStartIndex(), offsetSegment.get().getStopIndex(), ((NumberLiteralPaginationValueSegment) offsetSegment.get()).getValue())) : Optional.absent(); } - private Optional getLiteralOffsetSegment(final SelectStatement selectStatement) { - return isLiteralOffset(selectStatement) ? selectStatement.getLimit().getOffset() : Optional.absent(); + private Optional getLiteralOffsetSegment(final SelectStatement selectStatement) { + return isLiteralOffset(selectStatement) ? selectStatement.getPagination().getOffset() : Optional.absent(); } private boolean isLiteralOffset(final SelectStatement selectStatement) { - return null != selectStatement.getLimit() && selectStatement.getLimit().getOffset().isPresent() && selectStatement.getLimit().getOffset().get() instanceof NumberLiteralLimitValueSegment; + return null != selectStatement.getPagination() + && selectStatement.getPagination().getOffset().isPresent() && selectStatement.getPagination().getOffset().get() instanceof NumberLiteralPaginationValueSegment; } } diff --git a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/RowCountTokenGenerator.java b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/RowCountTokenGenerator.java index 1e8266df5d89a1859b2f754bc61227aa5c452c1f..e9af7345badb5f7bb45e7add6fb8f444c13eff3e 100644 --- a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/RowCountTokenGenerator.java +++ b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/generator/RowCountTokenGenerator.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.core.rewrite.token.generator; import com.google.common.base.Optional; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment; import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement; import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; import org.apache.shardingsphere.core.rewrite.token.pojo.RowCountToken; @@ -37,17 +37,18 @@ public final class RowCountTokenGenerator implements OptionalSQLTokenGenerator rowCountSegment = getLiteralRowCountSegment((SelectStatement) sqlStatement); + Optional rowCountSegment = getLiteralRowCountSegment((SelectStatement) sqlStatement); return rowCountSegment.isPresent() - ? Optional.of(new RowCountToken(rowCountSegment.get().getStartIndex(), rowCountSegment.get().getStopIndex(), ((NumberLiteralLimitValueSegment) rowCountSegment.get()).getValue())) + ? Optional.of(new RowCountToken(rowCountSegment.get().getStartIndex(), rowCountSegment.get().getStopIndex(), ((NumberLiteralPaginationValueSegment) rowCountSegment.get()).getValue())) : Optional.absent(); } - private Optional getLiteralRowCountSegment(final SelectStatement selectStatement) { - return isLiteralRowCount(selectStatement) ? selectStatement.getLimit().getRowCount() : Optional.absent(); + private Optional getLiteralRowCountSegment(final SelectStatement selectStatement) { + return isLiteralRowCount(selectStatement) ? selectStatement.getPagination().getRowCount() : Optional.absent(); } private boolean isLiteralRowCount(final SelectStatement selectStatement) { - return null != selectStatement.getLimit() && selectStatement.getLimit().getRowCount().isPresent() && selectStatement.getLimit().getRowCount().get() instanceof NumberLiteralLimitValueSegment; + return null != selectStatement.getPagination() && selectStatement.getPagination().getRowCount().isPresent() + && selectStatement.getPagination().getRowCount().get() instanceof NumberLiteralPaginationValueSegment; } } diff --git a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OffsetToken.java b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OffsetToken.java index bed732dc7127e95b0ad88aaa275c6cc1d3307065..67e952e9cc6c5b7017c695e8889734ff792ac678 100644 --- a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OffsetToken.java +++ b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/OffsetToken.java @@ -20,7 +20,7 @@ package org.apache.shardingsphere.core.rewrite.token.pojo; import lombok.Getter; /** - * Offset token for limit. + * Offset token for pagination. * * @author zhangliang * @author panjuan diff --git a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RowCountToken.java b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RowCountToken.java index c07f92207dbfc1e1871385433d3f06aa2ed3b64b..d08cdcc9ede2decbfc04d80b8dbe4d6214193fd6 100644 --- a/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RowCountToken.java +++ b/sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/token/pojo/RowCountToken.java @@ -20,7 +20,7 @@ package org.apache.shardingsphere.core.rewrite.token.pojo; import lombok.Getter; /** - * Row count token for limit. + * Row count token for pagination. * * @author zhangliang * @author panjuan diff --git a/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java b/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java index 212bc96a5dac6efcb4d8c12732c999f664fd4edd..5a686c3ba826d03db1bf1d84828b1c5655580ff6 100644 --- a/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java +++ b/sharding-core/sharding-core-rewrite/src/test/java/org/apache/shardingsphere/core/rewrite/rewriter/ShardingSQLRewriterTest.java @@ -46,9 +46,10 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.ExpressionSegme import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.item.AggregationDistinctSelectItemSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.order.item.ColumnOrderByItemSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.rownum.NumberLiteralRowNumberValueSegment; import org.apache.shardingsphere.core.parse.sql.segment.dml.predicate.PredicateSegment; import org.apache.shardingsphere.core.parse.sql.statement.dal.DALStatement; import org.apache.shardingsphere.core.parse.sql.statement.dml.DeleteStatement; @@ -346,8 +347,8 @@ public final class ShardingSQLRewriterTest { @Test public void assertRewriteForLimit() { - LimitSegment limitSegment = new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(33, 33, 2, true), new NumberLiteralLimitValueSegment(36, 36, 2, false)); - selectStatement.setLimit(limitSegment); + PaginationSegment limitSegment = new PaginationSegment(0, 0, new NumberLiteralLimitValueSegment(33, 33, 2), new NumberLiteralLimitValueSegment(36, 36, 2)); + selectStatement.setPagination(limitSegment); selectStatement.getSqlSegments().add(new TableSegment(17, 23, "table_x")); routeResult = new SQLRouteResult(selectStatement); routeResult.setLimit(new Limit(limitSegment, Collections.emptyList())); @@ -358,9 +359,9 @@ public final class ShardingSQLRewriterTest { } @Test - public void assertRewriteForRowNum() { - LimitSegment limitSegment = new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(119, 119, 2, true), new NumberLiteralLimitValueSegment(98, 98, 4, false)); - selectStatement.setLimit(limitSegment); + public void assertRewriteForRowNumber() { + PaginationSegment limitSegment = new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(119, 119, 2, true), new NumberLiteralRowNumberValueSegment(98, 98, 4, false)); + selectStatement.setPagination(limitSegment); selectStatement.getSqlSegments().add(new TableSegment(68, 74, "table_x")); routeResult = new SQLRouteResult(selectStatement); routeResult.setLimit(new Limit(limitSegment, Collections.emptyList())); @@ -373,8 +374,8 @@ public final class ShardingSQLRewriterTest { @Test public void assertRewriteForTopAndRowNumber() { - LimitSegment limitSegment = new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(123, 123, 2, true), new NumberLiteralLimitValueSegment(26, 26, 4, false)); - selectStatement.setLimit(limitSegment); + PaginationSegment limitSegment = new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(123, 123, 2, true), new NumberLiteralLimitValueSegment(26, 26, 4)); + selectStatement.setPagination(limitSegment); selectStatement.getSqlSegments().add(new TableSegment(85, 91, "table_x")); routeResult = new SQLRouteResult(selectStatement); routeResult.setLimit(new Limit(limitSegment, Collections.emptyList())); @@ -387,8 +388,8 @@ public final class ShardingSQLRewriterTest { @Test public void assertRewriteForLimitForMemoryGroupBy() { - LimitSegment limitSegment = new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(33, 33, 2, true), new NumberLiteralLimitValueSegment(36, 36, 2, false)); - selectStatement.setLimit(limitSegment); + PaginationSegment limitSegment = new PaginationSegment(0, 0, new NumberLiteralLimitValueSegment(33, 33, 2), new NumberLiteralLimitValueSegment(36, 36, 2)); + selectStatement.setPagination(limitSegment); ColumnSegment columnSegment = new ColumnSegment(0, 0, "id"); columnSegment.setOwner(new TableSegment(0, 0, "x")); selectStatement.getOrderByItems().add(new ColumnOrderByItemSegment(0, 0, columnSegment, OrderDirection.ASC, OrderDirection.ASC)); @@ -404,8 +405,8 @@ public final class ShardingSQLRewriterTest { @Test public void assertRewriteForRowNumForMemoryGroupBy() { - LimitSegment limitSegment = new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(119, 119, 2, true), new NumberLiteralLimitValueSegment(98, 98, 4, false)); - selectStatement.setLimit(limitSegment); + PaginationSegment limitSegment = new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(119, 119, 2, true), new NumberLiteralRowNumberValueSegment(98, 98, 4, false)); + selectStatement.setPagination(limitSegment); selectStatement.getSqlSegments().add(new TableSegment(68, 74, "table_x")); ColumnSegment columnSegment = new ColumnSegment(0, 0, "id"); columnSegment.setOwner(new TableSegment(0, 0, "x")); @@ -422,8 +423,8 @@ public final class ShardingSQLRewriterTest { @Test public void assertRewriteForTopAndRowNumberForMemoryGroupBy() { - LimitSegment limitSegment = new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(123, 123, 2, true), new NumberLiteralLimitValueSegment(26, 26, 4, false)); - selectStatement.setLimit(limitSegment); + PaginationSegment limitSegment = new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(123, 123, 2, false), new NumberLiteralLimitValueSegment(26, 26, 4)); + selectStatement.setPagination(limitSegment); selectStatement.getSqlSegments().add(new TableSegment(85, 91, "table_x")); ColumnSegment columnSegment = new ColumnSegment(0, 0, "id"); columnSegment.setOwner(new TableSegment(0, 0, "x")); @@ -440,8 +441,8 @@ public final class ShardingSQLRewriterTest { @Test public void assertRewriteForLimitForNotRewriteLimit() { - LimitSegment limitSegment = new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(33, 33, 2, true), new NumberLiteralLimitValueSegment(36, 36, 2, false)); - selectStatement.setLimit(limitSegment); + PaginationSegment limitSegment = new PaginationSegment(0, 0, new NumberLiteralLimitValueSegment(33, 33, 2), new NumberLiteralLimitValueSegment(36, 36, 2)); + selectStatement.setPagination(limitSegment); selectStatement.getSqlSegments().add(new TableSegment(17, 23, "table_x")); routeResult = new SQLRouteResult(selectStatement); routeResult.setLimit(new Limit(limitSegment, Collections.emptyList())); @@ -455,8 +456,8 @@ public final class ShardingSQLRewriterTest { @Test public void assertRewriteForRowNumForNotRewriteLimit() { - LimitSegment limitSegment = new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(119, 119, 2, true), new NumberLiteralLimitValueSegment(98, 98, 4, false)); - selectStatement.setLimit(limitSegment); + PaginationSegment limitSegment = new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(119, 119, 2, true), new NumberLiteralRowNumberValueSegment(98, 98, 4, false)); + selectStatement.setPagination(limitSegment); selectStatement.getSqlSegments().add(new TableSegment(68, 74, "table_x")); routeResult = new SQLRouteResult(selectStatement); routeResult.setLimit(new Limit(limitSegment, Collections.emptyList())); @@ -471,8 +472,8 @@ public final class ShardingSQLRewriterTest { @Test public void assertRewriteForTopAndRowNumberForNotRewriteLimit() { - LimitSegment limitSegment = new LimitSegment(0, 0, new NumberLiteralLimitValueSegment(123, 123, 2, true), new NumberLiteralLimitValueSegment(26, 26, 4, false)); - selectStatement.setLimit(limitSegment); + PaginationSegment limitSegment = new PaginationSegment(0, 0, new NumberLiteralRowNumberValueSegment(123, 123, 2, true), new NumberLiteralLimitValueSegment(26, 26, 4)); + selectStatement.setPagination(limitSegment); selectStatement.getSqlSegments().add(new TableSegment(85, 91, "table_x")); routeResult = new SQLRouteResult(selectStatement); routeResult.setLimit(new Limit(limitSegment, Collections.emptyList())); diff --git a/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/Limit.java b/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/Limit.java index 97cb03616d9b8b3ee6e4a944b91ab793225255c7..833b6ce153b2f9ff879c9ddfa713ad64a9408e36 100644 --- a/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/Limit.java +++ b/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/Limit.java @@ -18,10 +18,11 @@ package org.apache.shardingsphere.core.route.limit; import lombok.Getter; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.ParameterMarkerLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.NumberLiteralPaginationValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.ParameterMarkerPaginationValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.ParameterMarkerLimitValueSegment; import java.util.HashMap; import java.util.List; @@ -41,15 +42,16 @@ public final class Limit { private final LimitValue rowCount; - public Limit(final LimitSegment limitSegment, final List parameters) { + public Limit(final PaginationSegment limitSegment, final List parameters) { offset = limitSegment.getOffset().isPresent() ? createLimitValue(limitSegment.getOffset().get(), parameters) : null; rowCount = limitSegment.getRowCount().isPresent() ? createLimitValue(limitSegment.getRowCount().get(), parameters) : null; } - private LimitValue createLimitValue(final LimitValueSegment limitValueSegment, final List parameters) { - int segmentValue = limitValueSegment instanceof ParameterMarkerLimitValueSegment - ? (int) parameters.get(((ParameterMarkerLimitValueSegment) limitValueSegment).getParameterIndex()) : ((NumberLiteralLimitValueSegment) limitValueSegment).getValue(); - return new LimitValue(limitValueSegment, segmentValue); + private LimitValue createLimitValue(final PaginationValueSegment paginationValueSegment, final List parameters) { + int segmentValue = paginationValueSegment instanceof ParameterMarkerPaginationValueSegment + ? (int) parameters.get(((ParameterMarkerPaginationValueSegment) paginationValueSegment).getParameterIndex()) + : ((NumberLiteralPaginationValueSegment) paginationValueSegment).getValue(); + return new LimitValue(paginationValueSegment, segmentValue); } /** @@ -79,11 +81,11 @@ public final class Limit { */ public Map getRevisedParameters(final boolean isFetchAll, final String databaseType) { Map result = new HashMap<>(2, 1); - if (null != offset && offset.getLimitValueSegment() instanceof ParameterMarkerLimitValueSegment) { - result.put(((ParameterMarkerLimitValueSegment) offset.getLimitValueSegment()).getParameterIndex(), 0); + if (null != offset && offset.getPaginationValueSegment() instanceof ParameterMarkerLimitValueSegment) { + result.put(((ParameterMarkerLimitValueSegment) offset.getPaginationValueSegment()).getParameterIndex(), 0); } - if (null != rowCount && rowCount.getLimitValueSegment() instanceof ParameterMarkerLimitValueSegment) { - result.put(((ParameterMarkerLimitValueSegment) rowCount.getLimitValueSegment()).getParameterIndex(), getRewriteRowCount(isFetchAll, databaseType)); + if (null != rowCount && rowCount.getPaginationValueSegment() instanceof ParameterMarkerLimitValueSegment) { + result.put(((ParameterMarkerLimitValueSegment) rowCount.getPaginationValueSegment()).getParameterIndex(), getRewriteRowCount(isFetchAll, databaseType)); } return result; } diff --git a/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/LimitValue.java b/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/LimitValue.java index 35cb7164027b0dfc35f7df5c028e30960e628431..72ec486c0865e4701a326151aa091860ca4b1c51 100644 --- a/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/LimitValue.java +++ b/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/LimitValue.java @@ -19,7 +19,7 @@ package org.apache.shardingsphere.core.route.limit; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.PaginationValueSegment; /** * Limit value. @@ -30,7 +30,7 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegm @Getter public final class LimitValue { - private final LimitValueSegment limitValueSegment; + private final PaginationValueSegment paginationValueSegment; private final int value; } diff --git a/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/ParsingSQLRouter.java b/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/ParsingSQLRouter.java index 8fc66ae8af820e9ee8b4a11f8a6e8665c72ca5de..43def9920133b8109929e1a844d4f93dcd6bcfa8 100644 --- a/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/ParsingSQLRouter.java +++ b/sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/router/sharding/ParsingSQLRouter.java @@ -103,8 +103,8 @@ public final class ParsingSQLRouter implements ShardingRouter { mergeShardingValues(optimizeResult.getShardingConditions()); } RoutingResult routingResult = RoutingEngineFactory.newInstance(shardingRule, shardingMetaData.getDataSource(), sqlStatement, optimizeResult).route(); - if (sqlStatement instanceof SelectStatement && null != ((SelectStatement) sqlStatement).getLimit() && !routingResult.isSingleRouting()) { - result.setLimit(new Limit(((SelectStatement) sqlStatement).getLimit(), parameters)); + if (sqlStatement instanceof SelectStatement && null != ((SelectStatement) sqlStatement).getPagination() && !routingResult.isSingleRouting()) { + result.setLimit(new Limit(((SelectStatement) sqlStatement).getPagination(), parameters)); } if (needMerge) { Preconditions.checkState(1 == routingResult.getRoutingUnits().size(), "Must have one sharding with subquery."); diff --git a/sharding-core/sharding-core-route/src/test/java/org/apache/shardingsphere/core/route/DatabaseTest.java b/sharding-core/sharding-core-route/src/test/java/org/apache/shardingsphere/core/route/DatabaseTest.java index af039a92f2d84f4c1280b6bfee182cf96949026b..f2a1059e3d4dc9003206181c4f291750c2c8341b 100644 --- a/sharding-core/sharding-core-route/src/test/java/org/apache/shardingsphere/core/route/DatabaseTest.java +++ b/sharding-core/sharding-core-route/src/test/java/org/apache/shardingsphere/core/route/DatabaseTest.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.core.constant.DatabaseType; import org.apache.shardingsphere.core.metadata.ShardingMetaData; import org.apache.shardingsphere.core.metadata.table.ShardingTableMetaData; import org.apache.shardingsphere.core.parse.cache.ParsingResultCache; -import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment; +import org.apache.shardingsphere.core.parse.sql.segment.dml.pagination.limit.NumberLiteralLimitValueSegment; import org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement; import org.apache.shardingsphere.core.route.fixture.HintShardingAlgorithmFixture; import org.apache.shardingsphere.core.rule.ShardingRule; @@ -89,17 +89,17 @@ public final class DatabaseTest { String originSQL = "select user_id from tbl_pagination limit 0,5"; SQLRouteResult actual = new StatementRoutingEngine(shardingRule, mock(ShardingMetaData.class), DatabaseType.MySQL, new ParsingResultCache()).route(originSQL); SelectStatement selectStatement = (SelectStatement) actual.getSqlStatement(); - assertTrue(selectStatement.getLimit().getOffset().isPresent()); - assertThat(((NumberLiteralLimitValueSegment) selectStatement.getLimit().getOffset().get()).getValue(), is(0)); - assertTrue(selectStatement.getLimit().getRowCount().isPresent()); - assertThat(((NumberLiteralLimitValueSegment) selectStatement.getLimit().getRowCount().get()).getValue(), is(5)); + assertTrue(selectStatement.getPagination().getOffset().isPresent()); + assertThat(((NumberLiteralLimitValueSegment) selectStatement.getPagination().getOffset().get()).getValue(), is(0)); + assertTrue(selectStatement.getPagination().getRowCount().isPresent()); + assertThat(((NumberLiteralLimitValueSegment) selectStatement.getPagination().getRowCount().get()).getValue(), is(5)); originSQL = "select user_id from tbl_pagination limit 5,5"; actual = new StatementRoutingEngine(shardingRule, mock(ShardingMetaData.class), DatabaseType.MySQL, new ParsingResultCache()).route(originSQL); selectStatement = (SelectStatement) actual.getSqlStatement(); - assertTrue(selectStatement.getLimit().getOffset().isPresent()); - assertThat(((NumberLiteralLimitValueSegment) selectStatement.getLimit().getOffset().get()).getValue(), is(5)); - assertTrue(selectStatement.getLimit().getRowCount().isPresent()); - assertThat(((NumberLiteralLimitValueSegment) selectStatement.getLimit().getRowCount().get()).getValue(), is(5)); + assertTrue(selectStatement.getPagination().getOffset().isPresent()); + assertThat(((NumberLiteralLimitValueSegment) selectStatement.getPagination().getOffset().get()).getValue(), is(5)); + assertTrue(selectStatement.getPagination().getRowCount().isPresent()); + assertThat(((NumberLiteralLimitValueSegment) selectStatement.getPagination().getRowCount().get()).getValue(), is(5)); } @Test @@ -119,18 +119,18 @@ public final class DatabaseTest { when(shardingMetaData.getTable()).thenReturn(mock(ShardingTableMetaData.class)); SQLRouteResult actual = new PreparedStatementRoutingEngine(originSQL, rule, shardingMetaData, DatabaseType.MySQL, new ParsingResultCache()).route(Lists.newArrayList(13, 173)); SelectStatement selectStatement = (SelectStatement) actual.getSqlStatement(); - assertTrue(selectStatement.getLimit().getOffset().isPresent()); - assertThat(((NumberLiteralLimitValueSegment) selectStatement.getLimit().getOffset().get()).getValue(), is(5)); - assertTrue(selectStatement.getLimit().getRowCount().isPresent()); - assertThat(((NumberLiteralLimitValueSegment) selectStatement.getLimit().getRowCount().get()).getValue(), is(10)); + assertTrue(selectStatement.getPagination().getOffset().isPresent()); + assertThat(((NumberLiteralLimitValueSegment) selectStatement.getPagination().getOffset().get()).getValue(), is(5)); + assertTrue(selectStatement.getPagination().getRowCount().isPresent()); + assertThat(((NumberLiteralLimitValueSegment) selectStatement.getPagination().getRowCount().get()).getValue(), is(10)); assertThat(actual.getRoutingResult().getRoutingUnits().size(), is(1)); originSQL = "select city_id from t_user where city_id in (?,?) limit 5,10"; actual = new PreparedStatementRoutingEngine(originSQL, rule, shardingMetaData, DatabaseType.MySQL, new ParsingResultCache()).route(Lists.newArrayList(89, 84)); selectStatement = (SelectStatement) actual.getSqlStatement(); - assertTrue(selectStatement.getLimit().getOffset().isPresent()); - assertThat(((NumberLiteralLimitValueSegment) selectStatement.getLimit().getOffset().get()).getValue(), is(5)); - assertTrue(selectStatement.getLimit().getRowCount().isPresent()); - assertThat(((NumberLiteralLimitValueSegment) selectStatement.getLimit().getRowCount().get()).getValue(), is(10)); + assertTrue(selectStatement.getPagination().getOffset().isPresent()); + assertThat(((NumberLiteralLimitValueSegment) selectStatement.getPagination().getOffset().get()).getValue(), is(5)); + assertTrue(selectStatement.getPagination().getRowCount().isPresent()); + assertThat(((NumberLiteralLimitValueSegment) selectStatement.getPagination().getRowCount().get()).getValue(), is(10)); assertThat(actual.getRoutingResult().getRoutingUnits().size(), is(2)); }