use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngineTest method assertRewriteForTopAndRowNumber.
@Test
public void assertRewriteForTopAndRowNumber() {
selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
selectStatement.getLimit().setOffset(new LimitValue(2, -1, true));
selectStatement.getLimit().setRowCount(new LimitValue(4, -1, false));
selectStatement.getSqlTokens().add(new TableToken(85, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(123, 2));
selectStatement.getSqlTokens().add(new RowCountToken(26, 4));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_x x) AS row_ WHERE row_.rownum_>2", DatabaseType.SQLServer, selectStatement);
assertThat(rewriteEngine.rewrite(true).toSQL(tableTokens, null), is("SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_1 x) AS row_ WHERE row_.rownum_>0"));
}
use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngineTest method assertRewriteForTopAndRowNumberForMemoryGroupBy.
@Test
public void assertRewriteForTopAndRowNumberForMemoryGroupBy() {
selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
selectStatement.getLimit().setOffset(new LimitValue(2, -1, true));
selectStatement.getLimit().setRowCount(new LimitValue(4, -1, false));
selectStatement.getSqlTokens().add(new TableToken(85, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(123, 2));
selectStatement.getSqlTokens().add(new RowCountToken(26, 4));
selectStatement.getOrderByItems().add(new OrderItem("x", "id", OrderDirection.ASC, OrderDirection.ASC, Optional.<String>absent()));
selectStatement.getGroupByItems().add(new OrderItem("x", "id", OrderDirection.DESC, OrderDirection.ASC, Optional.<String>absent()));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT * FROM (SELECT TOP(4) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_x x) AS row_ WHERE row_.rownum_>2", DatabaseType.SQLServer, selectStatement);
assertThat(rewriteEngine.rewrite(true).toSQL(tableTokens, null), is("SELECT * FROM (SELECT TOP(2147483647) row_number() OVER (ORDER BY x.id) AS rownum_, x.id FROM table_1 x) AS row_ WHERE row_.rownum_>0"));
}
use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildGroupByStreamMergedResultWithMySQLLimit.
@Test
public void assertBuildGroupByStreamMergedResultWithMySQLLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.MySQL));
selectStatement.getGroupByItems().add(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC));
selectStatement.getOrderByItems().add(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class));
}
use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildGroupByStreamMergedResultWithOracleLimit.
@Test
public void assertBuildGroupByStreamMergedResultWithOracleLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.Oracle));
selectStatement.getGroupByItems().add(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC));
selectStatement.getOrderByItems().add(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class));
}
use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.
the class DQLMergeEngineTest method assertBuildOrderByStreamMergedResultWithOracleLimit.
@Test
public void assertBuildOrderByStreamMergedResultWithOracleLimit() throws SQLException {
selectStatement.setLimit(new Limit(DatabaseType.Oracle));
selectStatement.getOrderByItems().add(new OrderItem(1, OrderDirection.DESC, OrderDirection.ASC));
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(OrderByStreamMergedResult.class));
}
Aggregations