Search in sources :

Example 26 with Limit

use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.

the class TopAndRowNumberDecoratorMergedResultTest method assertNextWithOffsetWithoutRowCount.

@Test
public void assertNextWithOffsetWithoutRowCount() throws SQLException {
    Limit limit = new Limit(DatabaseType.SQLServer);
    limit.setOffset(new LimitValue(2, -1, true));
    selectStatement.setLimit(limit);
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    for (int i = 0; i < 7; i++) {
        assertTrue(actual.next());
    }
    assertFalse(actual.next());
}
Also used : MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Limit(io.shardingjdbc.core.parsing.parser.context.limit.Limit) LimitValue(io.shardingjdbc.core.parsing.parser.context.limit.LimitValue) Test(org.junit.Test)

Example 27 with Limit

use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.

the class TopAndRowNumberDecoratorMergedResultTest method assertNextForSkipAll.

@Test
public void assertNextForSkipAll() throws SQLException {
    Limit limit = new Limit(DatabaseType.SQLServer);
    limit.setOffset(new LimitValue(Integer.MAX_VALUE, -1, true));
    selectStatement.setLimit(limit);
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertFalse(actual.next());
}
Also used : MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Limit(io.shardingjdbc.core.parsing.parser.context.limit.Limit) LimitValue(io.shardingjdbc.core.parsing.parser.context.limit.LimitValue) Test(org.junit.Test)

Example 28 with Limit

use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.

the class SQLRewriteEngine method appendLimitRowCount.

private void appendLimitRowCount(final SQLBuilder sqlBuilder, final RowCountToken rowCountToken, final int count, final List<SQLToken> sqlTokens, final boolean isRewrite) {
    SelectStatement selectStatement = (SelectStatement) sqlStatement;
    Limit limit = selectStatement.getLimit();
    if (!isRewrite) {
        sqlBuilder.appendLiterals(String.valueOf(rowCountToken.getRowCount()));
    } else if ((!selectStatement.getGroupByItems().isEmpty() || !selectStatement.getAggregationSelectItems().isEmpty()) && !selectStatement.isSameGroupByAndOrderByItems()) {
        sqlBuilder.appendLiterals(String.valueOf(Integer.MAX_VALUE));
    } else {
        sqlBuilder.appendLiterals(String.valueOf(limit.isNeedRewriteRowCount() ? rowCountToken.getRowCount() + limit.getOffsetValue() : rowCountToken.getRowCount()));
    }
    int beginPosition = rowCountToken.getBeginPosition() + String.valueOf(rowCountToken.getRowCount()).length();
    appendRest(sqlBuilder, count, sqlTokens, beginPosition);
}
Also used : SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) Limit(io.shardingjdbc.core.parsing.parser.context.limit.Limit)

Example 29 with Limit

use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.

the class DQLMergeEngineTest method assertBuildIteratorStreamMergedResultWithSQLServerLimit.

@Test
public void assertBuildIteratorStreamMergedResultWithSQLServerLimit() throws SQLException {
    selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
    assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class));
}
Also used : TopAndRowNumberDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult) IteratorStreamMergedResult(io.shardingjdbc.core.merger.dql.iterator.IteratorStreamMergedResult) GroupByStreamMergedResult(io.shardingjdbc.core.merger.dql.groupby.GroupByStreamMergedResult) MergedResult(io.shardingjdbc.core.merger.MergedResult) LimitDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.LimitDecoratorMergedResult) GroupByMemoryMergedResult(io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult) TopAndRowNumberDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult) RowNumberDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.RowNumberDecoratorMergedResult) IteratorStreamMergedResult(io.shardingjdbc.core.merger.dql.iterator.IteratorStreamMergedResult) OrderByStreamMergedResult(io.shardingjdbc.core.merger.dql.orderby.OrderByStreamMergedResult) Limit(io.shardingjdbc.core.parsing.parser.context.limit.Limit) Test(org.junit.Test)

Example 30 with Limit

use of io.shardingjdbc.core.parsing.parser.context.limit.Limit in project sharding-jdbc by shardingjdbc.

the class DQLMergeEngineTest method assertBuildIteratorStreamMergedResultWithMySQLLimit.

@Test
public void assertBuildIteratorStreamMergedResultWithMySQLLimit() throws SQLException {
    selectStatement.setLimit(new Limit(DatabaseType.MySQL));
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
    assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(IteratorStreamMergedResult.class));
}
Also used : IteratorStreamMergedResult(io.shardingjdbc.core.merger.dql.iterator.IteratorStreamMergedResult) GroupByStreamMergedResult(io.shardingjdbc.core.merger.dql.groupby.GroupByStreamMergedResult) MergedResult(io.shardingjdbc.core.merger.MergedResult) LimitDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.LimitDecoratorMergedResult) GroupByMemoryMergedResult(io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult) TopAndRowNumberDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult) RowNumberDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.RowNumberDecoratorMergedResult) IteratorStreamMergedResult(io.shardingjdbc.core.merger.dql.iterator.IteratorStreamMergedResult) OrderByStreamMergedResult(io.shardingjdbc.core.merger.dql.orderby.OrderByStreamMergedResult) Limit(io.shardingjdbc.core.parsing.parser.context.limit.Limit) LimitDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.LimitDecoratorMergedResult) Test(org.junit.Test)

Aggregations

Limit (io.shardingjdbc.core.parsing.parser.context.limit.Limit)46 Test (org.junit.Test)36 MergedResult (io.shardingjdbc.core.merger.MergedResult)27 LimitValue (io.shardingjdbc.core.parsing.parser.context.limit.LimitValue)27 GroupByMemoryMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult)15 GroupByStreamMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByStreamMergedResult)15 IteratorStreamMergedResult (io.shardingjdbc.core.merger.dql.iterator.IteratorStreamMergedResult)15 OrderByStreamMergedResult (io.shardingjdbc.core.merger.dql.orderby.OrderByStreamMergedResult)15 LimitDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.LimitDecoratorMergedResult)15 RowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.RowNumberDecoratorMergedResult)15 TopAndRowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult)15 RowCountToken (io.shardingjdbc.core.parsing.parser.token.RowCountToken)14 DQLMergeEngine (io.shardingjdbc.core.merger.dql.DQLMergeEngine)12 OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)12 OffsetToken (io.shardingjdbc.core.parsing.parser.token.OffsetToken)12 TableToken (io.shardingjdbc.core.parsing.parser.token.TableToken)9 SQLParsingException (io.shardingjdbc.core.parsing.parser.exception.SQLParsingException)5 AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)3 SQLExpression (io.shardingjdbc.core.parsing.parser.expression.SQLExpression)3 SQLNumberExpression (io.shardingjdbc.core.parsing.parser.expression.SQLNumberExpression)3