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));
}
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));
}
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));
}
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++;
}
}
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);
}
}
Aggregations