Search in sources :

Example 6 with AggregationSelectItem

use of io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem 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 7 with AggregationSelectItem

use of io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem in project sharding-jdbc by shardingjdbc.

the class GroupByMemoryMergedResultTest method setUp.

@Before
public void setUp() throws SQLException {
    resultSets = Lists.newArrayList(mockResultSet(), mockResultSet(), mockResultSet());
    queryResults = new ArrayList<>(resultSets.size());
    for (ResultSet each : resultSets) {
        queryResults.add(new TestQueryResult(each));
    }
    selectStatement = new SelectStatement();
    AggregationSelectItem aggregationSelectItem1 = new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent());
    aggregationSelectItem1.setIndex(1);
    AggregationSelectItem aggregationSelectItem2 = new AggregationSelectItem(AggregationType.AVG, "(num)", Optional.<String>absent());
    aggregationSelectItem2.setIndex(2);
    AggregationSelectItem derivedAggregationSelectItem1 = new AggregationSelectItem(AggregationType.COUNT, "(num)", Optional.of("AVG_DERIVED_COUNT_0"));
    aggregationSelectItem2.setIndex(4);
    aggregationSelectItem2.getDerivedAggregationSelectItems().add(derivedAggregationSelectItem1);
    AggregationSelectItem derivedAggregationSelectItem2 = new AggregationSelectItem(AggregationType.SUM, "(num)", Optional.of("AVG_DERIVED_SUM_0"));
    aggregationSelectItem2.setIndex(5);
    aggregationSelectItem2.getDerivedAggregationSelectItems().add(derivedAggregationSelectItem2);
    selectStatement.getItems().add(aggregationSelectItem1);
    selectStatement.getItems().add(aggregationSelectItem2);
    selectStatement.getGroupByItems().add(new OrderItem(3, OrderDirection.ASC, OrderDirection.ASC));
    selectStatement.getOrderByItems().add(new OrderItem(3, OrderDirection.DESC, OrderDirection.ASC));
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) ResultSet(java.sql.ResultSet) Before(org.junit.Before)

Example 8 with AggregationSelectItem

use of io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem in project sharding-jdbc by shardingjdbc.

the class GroupByStreamMergedResultTest method setUp.

@Before
public void setUp() throws SQLException {
    resultSets = Lists.newArrayList(mockResultSet(), mockResultSet(), mockResultSet());
    queryResults = new ArrayList<>(resultSets.size());
    for (ResultSet each : resultSets) {
        queryResults.add(new TestQueryResult(each));
    }
    selectStatement = new SelectStatement();
    AggregationSelectItem aggregationSelectItem1 = new AggregationSelectItem(AggregationType.COUNT, "(*)", Optional.<String>absent());
    aggregationSelectItem1.setIndex(1);
    AggregationSelectItem aggregationSelectItem2 = new AggregationSelectItem(AggregationType.AVG, "(num)", Optional.<String>absent());
    aggregationSelectItem2.setIndex(2);
    AggregationSelectItem derivedAggregationSelectItem1 = new AggregationSelectItem(AggregationType.COUNT, "(num)", Optional.of("AVG_DERIVED_COUNT_0"));
    aggregationSelectItem2.setIndex(5);
    aggregationSelectItem2.getDerivedAggregationSelectItems().add(derivedAggregationSelectItem1);
    AggregationSelectItem derivedAggregationSelectItem2 = new AggregationSelectItem(AggregationType.SUM, "(num)", Optional.of("AVG_DERIVED_SUM_0"));
    aggregationSelectItem2.setIndex(6);
    aggregationSelectItem2.getDerivedAggregationSelectItems().add(derivedAggregationSelectItem2);
    selectStatement.getItems().add(aggregationSelectItem1);
    selectStatement.getItems().add(aggregationSelectItem2);
    selectStatement.getGroupByItems().add(new OrderItem(3, OrderDirection.ASC, OrderDirection.ASC));
    selectStatement.getOrderByItems().add(new OrderItem(3, OrderDirection.ASC, OrderDirection.ASC));
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) TestQueryResult(io.shardingjdbc.core.merger.fixture.TestQueryResult) SelectStatement(io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement) OrderItem(io.shardingjdbc.core.parsing.parser.context.OrderItem) ResultSet(java.sql.ResultSet) Before(org.junit.Before)

Example 9 with AggregationSelectItem

use of io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem in project sharding-jdbc by shardingjdbc.

the class AggregationSelectItemAssert method assertAggregationSelectItem.

private void assertAggregationSelectItem(final AggregationSelectItem actual, final ExpectedAggregationSelectItem expected) {
    assertThat(assertMessage.getFullAssertMessage("Aggregation select item aggregation type assertion error: "), actual.getType().name(), is(expected.getType()));
    assertThat(assertMessage.getFullAssertMessage("Aggregation select item inner expression assertion error: "), actual.getInnerExpression(), is(expected.getInnerExpression()));
    assertThat(assertMessage.getFullAssertMessage("Aggregation select item alias assertion error: "), actual.getAlias().orNull(), is(expected.getAlias()));
    assertThat(assertMessage.getFullAssertMessage("Aggregation select item index assertion error: "), actual.getIndex(), is(expected.getIndex()));
    assertThat(assertMessage.getFullAssertMessage("Aggregation select item derived aggregation select items assertion error: "), actual.getDerivedAggregationSelectItems().size(), is(expected.getDerivedColumns().size()));
    int count = 0;
    for (AggregationSelectItem each : actual.getDerivedAggregationSelectItems()) {
        assertAggregationSelectItem(each, expected.getDerivedColumns().get(count));
        count++;
    }
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) ExpectedAggregationSelectItem(io.shardingjdbc.core.parsing.integrate.jaxb.item.ExpectedAggregationSelectItem)

Example 10 with AggregationSelectItem

use of io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem in project sharding-jdbc by shardingjdbc.

the class GroupByMemoryMergedResult method initForFirstGroupByValue.

private void initForFirstGroupByValue(final QueryResult queryResult, final GroupByValue groupByValue, final Map<GroupByValue, MemoryQueryResultRow> dataMap, final Map<GroupByValue, Map<AggregationSelectItem, AggregationUnit>> aggregationMap) throws SQLException {
    if (!dataMap.containsKey(groupByValue)) {
        dataMap.put(groupByValue, new MemoryQueryResultRow(queryResult));
    }
    if (!aggregationMap.containsKey(groupByValue)) {
        Map<AggregationSelectItem, AggregationUnit> map = Maps.toMap(selectStatement.getAggregationSelectItems(), new Function<AggregationSelectItem, AggregationUnit>() {

            @Override
            public AggregationUnit apply(final AggregationSelectItem input) {
                return AggregationUnitFactory.create(input.getType());
            }
        });
        aggregationMap.put(groupByValue, map);
    }
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) MemoryQueryResultRow(io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow) AggregationUnit(io.shardingjdbc.core.merger.dql.groupby.aggregation.AggregationUnit)

Aggregations

AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)15 GroupByMemoryMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByMemoryMergedResult)4 Test (org.junit.Test)4 MergedResult (io.shardingjdbc.core.merger.MergedResult)3 GroupByStreamMergedResult (io.shardingjdbc.core.merger.dql.groupby.GroupByStreamMergedResult)3 IteratorStreamMergedResult (io.shardingjdbc.core.merger.dql.iterator.IteratorStreamMergedResult)3 OrderByStreamMergedResult (io.shardingjdbc.core.merger.dql.orderby.OrderByStreamMergedResult)3 LimitDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.LimitDecoratorMergedResult)3 RowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.RowNumberDecoratorMergedResult)3 TopAndRowNumberDecoratorMergedResult (io.shardingjdbc.core.merger.dql.pagination.TopAndRowNumberDecoratorMergedResult)3 Limit (io.shardingjdbc.core.parsing.parser.context.limit.Limit)3 AggregationUnit (io.shardingjdbc.core.merger.dql.groupby.aggregation.AggregationUnit)2 TestQueryResult (io.shardingjdbc.core.merger.fixture.TestQueryResult)2 ExpectedAggregationSelectItem (io.shardingjdbc.core.parsing.integrate.jaxb.item.ExpectedAggregationSelectItem)2 OrderItem (io.shardingjdbc.core.parsing.parser.context.OrderItem)2 SelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.SelectItem)2 SelectStatement (io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2