public static GroupingSetDescriptor globalAggregation() { return singleGroupingSet(ImmutableList.of()); }
public static GroupingSetDescriptor globalAggregation() { return singleGroupingSet(ImmutableList.of()); }
private PlanNode distinct(PlanNode node) { return new AggregationNode(idAllocator.getNextId(), node, ImmutableMap.of(), singleGroupingSet(node.getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty()); }
private PlanNode distinct(PlanNode node) { return new AggregationNode(idAllocator.getNextId(), node, ImmutableMap.of(), singleGroupingSet(node.getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty()); }
private AggregationNode computeCounts(UnionNode sourceNode, List<Symbol> originalColumns, List<Symbol> markers, List<Symbol> aggregationOutputs) { ImmutableMap.Builder<Symbol, Aggregation> aggregations = ImmutableMap.builder(); for (int i = 0; i < markers.size(); i++) { Symbol output = aggregationOutputs.get(i); aggregations.put(output, new Aggregation( new FunctionCall(QualifiedName.of("count"), ImmutableList.of(markers.get(i).toSymbolReference())), COUNT_AGGREGATION, Optional.empty())); } return new AggregationNode(idAllocator.getNextId(), sourceNode, aggregations.build(), singleGroupingSet(originalColumns), ImmutableList.of(), Step.SINGLE, Optional.empty(), Optional.empty()); }
private AggregationNode computeCounts(UnionNode sourceNode, List<Symbol> originalColumns, List<Symbol> markers, List<Symbol> aggregationOutputs) { ImmutableMap.Builder<Symbol, Aggregation> aggregations = ImmutableMap.builder(); for (int i = 0; i < markers.size(); i++) { Symbol output = aggregationOutputs.get(i); aggregations.put(output, new Aggregation( new FunctionCall(QualifiedName.of("count"), ImmutableList.of(markers.get(i).toSymbolReference())), COUNT_AGGREGATION, Optional.empty())); } return new AggregationNode(idAllocator.getNextId(), sourceNode, aggregations.build(), singleGroupingSet(originalColumns), ImmutableList.of(), Step.SINGLE, Optional.empty(), Optional.empty()); }
public AggregationBuilder singleGroupingSet(Symbol... symbols) { groupingSets(AggregationNode.singleGroupingSet(ImmutableList.copyOf(symbols))); return this; }
public AggregationBuilder globalGrouping() { groupingSets(AggregationNode.singleGroupingSet(ImmutableList.of())); return this; }
public AggregationBuilder singleGroupingSet(Symbol... symbols) { groupingSets(AggregationNode.singleGroupingSet(ImmutableList.copyOf(symbols))); return this; }
public AggregationBuilder globalGrouping() { groupingSets(AggregationNode.singleGroupingSet(ImmutableList.of())); return this; }
private PlanBuilder distinct(PlanBuilder subPlan, QuerySpecification node) { if (node.getSelect().isDistinct()) { return subPlan.withNewRoot( new AggregationNode( idAllocator.getNextId(), subPlan.getRoot(), ImmutableMap.of(), singleGroupingSet(subPlan.getRoot().getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty())); } return subPlan; }
private PlanBuilder distinct(PlanBuilder subPlan, QuerySpecification node) { if (node.getSelect().isDistinct()) { return subPlan.withNewRoot( new AggregationNode( idAllocator.getNextId(), subPlan.getRoot(), ImmutableMap.of(), singleGroupingSet(subPlan.getRoot().getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty())); } return subPlan; }
private AggregationNode replaceAggregationSource( AggregationNode aggregation, PlanNode source, List<Symbol> groupingKeys) { return new AggregationNode( aggregation.getId(), source, aggregation.getAggregations(), singleGroupingSet(groupingKeys), ImmutableList.of(), aggregation.getStep(), aggregation.getHashSymbol(), aggregation.getGroupIdSymbol()); }
private AggregationNode replaceAggregationSource( AggregationNode aggregation, PlanNode source, List<Symbol> groupingKeys) { return new AggregationNode( aggregation.getId(), source, aggregation.getAggregations(), singleGroupingSet(groupingKeys), ImmutableList.of(), aggregation.getStep(), aggregation.getHashSymbol(), aggregation.getGroupIdSymbol()); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint") public void testInvalidAggregationFunctionCall() { Symbol aggregationSymbol = symbolAllocator.newSymbol("sum", DOUBLE); PlanNode node = new AggregationNode( newId(), baseTableScan, ImmutableMap.of(aggregationSymbol, new Aggregation( new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(columnA.toSymbolReference())), new Signature( "sum", FunctionKind.AGGREGATE, ImmutableList.of(), ImmutableList.of(), DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()), false), Optional.empty())), singleGroupingSet(ImmutableList.of(columnA, columnB)), ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty()); assertTypesValid(node); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint") public void testInvalidAggregationFunctionCall() { Symbol aggregationSymbol = symbolAllocator.newSymbol("sum", DOUBLE); PlanNode node = new AggregationNode( newId(), baseTableScan, ImmutableMap.of(aggregationSymbol, new Aggregation( new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(columnA.toSymbolReference())), new Signature( "sum", FunctionKind.AGGREGATE, ImmutableList.of(), ImmutableList.of(), DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()), false), Optional.empty())), singleGroupingSet(ImmutableList.of(columnA, columnB)), ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty()); assertTypesValid(node); }
private AggregationNode aggregation(String id, PlanNode source) { AggregationNode.Aggregation aggregation = new AggregationNode.Aggregation( new FunctionCall(QualifiedName.of("count"), ImmutableList.of()), new Signature("count", AGGREGATE, parseTypeSignature(StandardTypes.BIGINT)), Optional.empty()); return new AggregationNode( new PlanNodeId(id), source, ImmutableMap.of(new Symbol("count"), aggregation), singleGroupingSet(source.getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.FINAL, Optional.empty(), Optional.empty()); }
private AggregationNode aggregation(String id, PlanNode source) { AggregationNode.Aggregation aggregation = new AggregationNode.Aggregation( new FunctionCall(QualifiedName.of("count"), ImmutableList.of()), new Signature("count", AGGREGATE, parseTypeSignature(StandardTypes.BIGINT)), Optional.empty()); return new AggregationNode( new PlanNodeId(id), source, ImmutableMap.of(new Symbol("count"), aggregation), singleGroupingSet(source.getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.FINAL, Optional.empty(), Optional.empty()); }
@Test public void testDoesNotFireOnNestedCountAggregateWithNonEmptyGroupBy() { tester().assertThat(new PruneCountAggregationOverScalar()) .on(p -> p.aggregation((a) -> a .addAggregation( p.symbol("count_1", BigintType.BIGINT), new FunctionCall(QualifiedName.of("count"), ImmutableList.of()), ImmutableList.of(BigintType.BIGINT)) .step(AggregationNode.Step.SINGLE) .globalGrouping() .source( p.aggregation(aggregationBuilder -> { aggregationBuilder .source(p.tableScan(ImmutableList.of(), ImmutableMap.of())).groupingSets(singleGroupingSet(ImmutableList.of(p.symbol("orderkey")))); aggregationBuilder .source(p.tableScan(ImmutableList.of(), ImmutableMap.of())); })))) .doesNotFire(); }
@Test public void testDoesNotFireOnNestedCountAggregateWithNonEmptyGroupBy() { tester().assertThat(new PruneCountAggregationOverScalar()) .on(p -> p.aggregation((a) -> a .addAggregation( p.symbol("count_1", BigintType.BIGINT), new FunctionCall(QualifiedName.of("count"), ImmutableList.of()), ImmutableList.of(BigintType.BIGINT)) .step(AggregationNode.Step.SINGLE) .globalGrouping() .source( p.aggregation(aggregationBuilder -> { aggregationBuilder .source(p.tableScan(ImmutableList.of(), ImmutableMap.of())).groupingSets(singleGroupingSet(ImmutableList.of(p.symbol("orderkey")))); aggregationBuilder .source(p.tableScan(ImmutableList.of(), ImmutableMap.of())); })))) .doesNotFire(); }