use of io.shardingjdbc.core.parsing.parser.context.limit.LimitValue in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngineTest method assertRewriteForLimitForNotRewriteLimit.
@Test
public void assertRewriteForLimitForNotRewriteLimit() {
selectStatement.setLimit(new Limit(DatabaseType.MySQL));
selectStatement.getLimit().setOffset(new LimitValue(2, -1, true));
selectStatement.getLimit().setRowCount(new LimitValue(2, -1, false));
selectStatement.getSqlTokens().add(new TableToken(17, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(33, 2));
selectStatement.getSqlTokens().add(new RowCountToken(36, 2));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT x.id FROM table_x x LIMIT 2, 2", DatabaseType.MySQL, selectStatement);
assertThat(rewriteEngine.rewrite(false).toSQL(tableTokens, null), is("SELECT x.id FROM table_1 x LIMIT 2, 2"));
}
use of io.shardingjdbc.core.parsing.parser.context.limit.LimitValue in project sharding-jdbc by shardingjdbc.
the class SQLRewriteEngineTest method assertRewriteForLimit.
@Test
public void assertRewriteForLimit() {
selectStatement.setLimit(new Limit(DatabaseType.MySQL));
selectStatement.getLimit().setOffset(new LimitValue(2, -1, true));
selectStatement.getLimit().setRowCount(new LimitValue(2, -1, false));
selectStatement.getSqlTokens().add(new TableToken(17, "table_x"));
selectStatement.getSqlTokens().add(new OffsetToken(33, 2));
selectStatement.getSqlTokens().add(new RowCountToken(36, 2));
SQLRewriteEngine rewriteEngine = new SQLRewriteEngine(shardingRule, "SELECT x.id FROM table_x x LIMIT 2, 2", DatabaseType.MySQL, selectStatement);
assertThat(rewriteEngine.rewrite(true).toSQL(tableTokens, null), is("SELECT x.id FROM table_1 x LIMIT 0, 4"));
}
use of io.shardingjdbc.core.parsing.parser.context.limit.LimitValue 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.LimitValue 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.LimitValue in project sharding-jdbc by shardingjdbc.
the class LimitDecoratorMergedResultTest method assertNextWithoutRowCount.
@Test
public void assertNextWithoutRowCount() throws SQLException {
Limit limit = new Limit(DatabaseType.MySQL);
limit.setOffset(new LimitValue(2, -1, true));
selectStatement.setLimit(limit);
mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
MergedResult actual = mergeEngine.merge();
for (int i = 0; i < 6; i++) {
assertTrue(actual.next());
}
assertFalse(actual.next());
}
Aggregations