Search in sources :

Example 1 with AggregationUnit

use of io.shardingjdbc.core.merger.dql.groupby.aggregation.AggregationUnit in project sharding-jdbc by shardingjdbc.

the class GroupByStreamMergedResult method aggregate.

private void aggregate(final Map<AggregationSelectItem, AggregationUnit> aggregationUnitMap) throws SQLException {
    for (Entry<AggregationSelectItem, AggregationUnit> entry : aggregationUnitMap.entrySet()) {
        List<Comparable<?>> values = new ArrayList<>(2);
        if (entry.getKey().getDerivedAggregationSelectItems().isEmpty()) {
            values.add(getAggregationValue(entry.getKey()));
        } else {
            for (AggregationSelectItem each : entry.getKey().getDerivedAggregationSelectItems()) {
                values.add(getAggregationValue(each));
            }
        }
        entry.getValue().merge(values);
    }
}
Also used : AggregationSelectItem(io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem) AggregationUnit(io.shardingjdbc.core.merger.dql.groupby.aggregation.AggregationUnit) ArrayList(java.util.ArrayList)

Example 2 with AggregationUnit

use of io.shardingjdbc.core.merger.dql.groupby.aggregation.AggregationUnit 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

AggregationUnit (io.shardingjdbc.core.merger.dql.groupby.aggregation.AggregationUnit)2 AggregationSelectItem (io.shardingjdbc.core.parsing.parser.context.selectitem.AggregationSelectItem)2 MemoryQueryResultRow (io.shardingjdbc.core.merger.dql.common.MemoryQueryResultRow)1 ArrayList (java.util.ArrayList)1