Search in sources :

Example 6 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class DQLMergeEngineTest method assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithSQLServerLimit.

@Test
public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithSQLServerLimit() throws SQLException {
    selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
    selectStatement.getItems().add(new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent()));
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertThat(actual, instanceOf(TopAndRowNumberDecoratorMergedResult.class));
    assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class));
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) TopAndRowNumberDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult) 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) GroupByMemoryMergedResult(io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult) Limit(io.shardingjdbc.core.parsing.parser.context.limit.Limit) Test(org.junit.Test)

Example 7 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class DQLMergeEngineTest method assertBuildGroupByStreamMergedResultWithSQLServerLimit.

@Test
public void assertBuildGroupByStreamMergedResultWithSQLServerLimit() throws SQLException {
    selectStatement.setLimit(new Limit(DatabaseType.SQLServer));
    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(TopAndRowNumberDecoratorMergedResult.class));
    assertThat(((TopAndRowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByStreamMergedResult.class));
}
Also used : TopAndRowNumberDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) 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) GroupByStreamMergedResult(io.shardingjdbc.core.merger.dql.groupby.GroupByStreamMergedResult) Test(org.junit.Test)

Example 8 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class DQLMergeEngineTest method assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithMySQLLimit.

@Test
public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithMySQLLimit() throws SQLException {
    selectStatement.setLimit(new Limit(DatabaseType.MySQL));
    selectStatement.getItems().add(new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent()));
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertThat(actual, instanceOf(LimitDecoratorMergedResult.class));
    assertThat(((LimitDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class));
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) 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) GroupByMemoryMergedResult(io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult) Limit(io.shardingjdbc.core.parsing.parser.context.limit.Limit) LimitDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.LimitDecoratorMergedResult) Test(org.junit.Test)

Example 9 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class DQLMergeEngineTest method assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLimit.

@Test
public void assertBuildGroupByMemoryMergedResultWithAggregationOnlyWithOracleLimit() throws SQLException {
    selectStatement.setLimit(new Limit(DatabaseType.Oracle));
    selectStatement.getItems().add(new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent()));
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    MergedResult actual = mergeEngine.merge();
    assertThat(actual, instanceOf(RowNumberDecoratorMergedResult.class));
    assertThat(((RowNumberDecoratorMergedResult) actual).getMergedResult(), instanceOf(GroupByMemoryMergedResult.class));
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) TopAndRowNumberDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult) RowNumberDecoratorMergedResult(io.shardingjdbc.core.merger.dql.pagination.RowNumberDecoratorMergedResult) 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) GroupByMemoryMergedResult(io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult) Limit(io.shardingjdbc.core.parsing.parser.context.limit.Limit) Test(org.junit.Test)

Example 10 with MergedResult

use of io.shardingjdbc.core.merger.MergedResult in project sharding-jdbc by shardingjdbc.

the class GroupByStreamMergedResultTest method assertNextForSomeResultSetsEmpty.

@Test
public void assertNextForSomeResultSetsEmpty() throws SQLException {
    mergeEngine = new DQLMergeEngine(queryResults, selectStatement);
    when(resultSets.get(0).next()).thenReturn(true, false);
    when(resultSets.get(0).getObject(1)).thenReturn(20);
    when(resultSets.get(0).getObject(2)).thenReturn(0);
    when(resultSets.get(0).getObject(3)).thenReturn(2);
    when(resultSets.get(0).getObject(4)).thenReturn(new Date(0L));
    when(resultSets.get(0).getObject(5)).thenReturn(2);
    when(resultSets.get(0).getObject(6)).thenReturn(20);
    when(resultSets.get(2).next()).thenReturn(true, true, false);
    when(resultSets.get(2).getObject(1)).thenReturn(20, 30);
    when(resultSets.get(2).getObject(2)).thenReturn(0);
    when(resultSets.get(2).getObject(3)).thenReturn(2, 2, 3);
    when(resultSets.get(2).getObject(4)).thenReturn(new Date(0L));
    when(resultSets.get(2).getObject(5)).thenReturn(2, 2, 3);
    when(resultSets.get(2).getObject(6)).thenReturn(20, 20, 30);
    MergedResult actual = mergeEngine.merge();
    assertTrue(actual.next());
    assertThat((BigDecimal) actual.getValue(1, Object.class), is(new BigDecimal(40)));
    assertThat((BigDecimal) actual.getValue("COUNT(*)", Object.class), is(new BigDecimal(40)));
    assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10));
    assertThat(((BigDecimal) actual.getValue("avg(NUM)", Object.class)).intValue(), is(10));
    assertThat((Integer) actual.getValue(3, Object.class), is(2));
    assertThat((Integer) actual.getValue("ID", Object.class), is(2));
    assertThat((Date) actual.getCalendarValue(4, Date.class, Calendar.getInstance()), is(new Date(0L)));
    assertThat((Date) actual.getCalendarValue("date", Date.class, Calendar.getInstance()), is(new Date(0L)));
    assertThat((BigDecimal) actual.getValue(5, Object.class), is(new BigDecimal(4)));
    assertThat((BigDecimal) actual.getValue("AVG_DERIVED_COUNT_0", Object.class), is(new BigDecimal(4)));
    assertThat((BigDecimal) actual.getValue(6, Object.class), is(new BigDecimal(40)));
    assertThat((BigDecimal) actual.getValue("Avg_Derived_Sum_0", Object.class), is(new BigDecimal(40)));
    assertTrue(actual.next());
    assertThat((BigDecimal) actual.getValue(1, Object.class), is(new BigDecimal(30)));
    assertThat(((BigDecimal) actual.getValue(2, Object.class)).intValue(), is(10));
    assertThat((Integer) actual.getValue(3, Object.class), is(3));
    assertThat((Date) actual.getCalendarValue(4, Date.class, Calendar.getInstance()), is(new Date(0L)));
    assertThat((Date) actual.getCalendarValue("date", Date.class, Calendar.getInstance()), is(new Date(0L)));
    assertThat((BigDecimal) actual.getValue(5, Object.class), is(new BigDecimal(3)));
    assertThat((BigDecimal) actual.getValue(6, Object.class), is(new BigDecimal(30)));
    assertFalse(actual.next());
}
Also used : MergedResult(io.shardingjdbc.core.merger.MergedResult) DQLMergeEngine(io.shardingjdbc.core.merger.dql.DQLMergeEngine) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

MergedResult (io.shardingjdbc.core.merger.MergedResult)42 Test (org.junit.Test)41 Limit (io.shardingjdbc.core.parsing.parser.context.limit.Limit)27 DQLMergeEngine (io.shardingjdbc.core.merger.dql.DQLMergeEngine)26 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 LimitValue (io.shardingjdbc.core.parsing.parser.context.limit.LimitValue)11 OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)9 AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)3 BigDecimal (java.math.BigDecimal)3 QueryResult (io.shardingjdbc.core.merger.QueryResult)2 TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)2 MySQLPacketQueryResult (io.shardingjdbc.proxy.backend.mysql.MySQLPacketQueryResult)1 DatabaseProtocolPacket (io.shardingjdbc.proxy.transport.common.packet.DatabaseProtocolPacket)1 ErrPacket (io.shardingjdbc.proxy.transport.mysql.packet.generic.ErrPacket)1