return aggregate.copy(aggregate.getTraitSet(), project, false, ImmutableBitSet.range(projects.size()), null, ImmutableList.<AggregateCall>of());
public RelNode align(Aggregate rel, List<RelFieldCollation> collations) { // 1) We extract the group by positions that are part of the collations and // sort them so they respect it LinkedHashSet<Integer> aggregateColumnsOrder = new LinkedHashSet<>(); ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder(); if (rel.getGroupType() == Group.SIMPLE && !collations.isEmpty()) { for (RelFieldCollation c : collations) { if (c.getFieldIndex() < rel.getGroupCount()) { // Group column found if (aggregateColumnsOrder.add(c.getFieldIndex())) { propagateCollations.add(c.copy(rel.getGroupSet().nth(c.getFieldIndex()))); } } } } for (int i = 0; i < rel.getGroupCount(); i++) { if (!aggregateColumnsOrder.contains(i)) { // Not included in the input collations, but can be propagated as this Aggregate // will enforce it propagateCollations.add(new RelFieldCollation(rel.getGroupSet().nth(i))); } } // 2) We propagate final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build()); // 3) We annotate the Aggregate operator with this info final HiveAggregate newAggregate = (HiveAggregate) rel.copy(rel.getTraitSet(), ImmutableList.of(child)); newAggregate.setAggregateColumnsOrder(aggregateColumnsOrder); return newAggregate; }
rewriteAggCalls(newAggCalls, argList, sourceOf); final int cardinality = aggregate.getGroupSet().cardinality(); return aggregate.copy(aggregate.getTraitSet(), distinct, aggregate.indicator, ImmutableBitSet.range(cardinality), null, newAggCalls);
return aggregate.copy(aggregate.getTraitSet(), project, false, ImmutableBitSet.range(projects.size()), null, ImmutableList.<AggregateCall>of());
final Aggregate newAggregate = aggRel.copy(aggRel.getTraitSet(), aggRel.getInput(), aggRel.indicator, aggRel.getGroupSet(), aggRel.getGroupSets(), newAggCalls);
rewriteAggCalls(newAggCalls, argList, sourceOf); final int cardinality = aggregate.getGroupSet().cardinality(); return aggregate.copy(aggregate.getTraitSet(), distinct, aggregate.indicator, ImmutableBitSet.range(cardinality), null, newAggCalls);
aggregate.getTraitSet(), aggregate.getInput(), aggregate.indicator,
public RelNode align(Aggregate rel, List<RelFieldCollation> collations) { // 1) We extract the group by positions that are part of the collations and // sort them so they respect it LinkedHashSet<Integer> aggregateColumnsOrder = new LinkedHashSet<>(); ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder(); if (!rel.indicator && !collations.isEmpty()) { for (RelFieldCollation c : collations) { if (c.getFieldIndex() < rel.getGroupCount()) { // Group column found if (aggregateColumnsOrder.add(c.getFieldIndex())) { propagateCollations.add(c.copy(rel.getGroupSet().nth(c.getFieldIndex()))); } } } } for (int i = 0; i < rel.getGroupCount(); i++) { if (!aggregateColumnsOrder.contains(i)) { // Not included in the input collations, but can be propagated as this Aggregate // will enforce it propagateCollations.add(new RelFieldCollation(rel.getGroupSet().nth(i))); } } // 2) We propagate final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build()); // 3) We annotate the Aggregate operator with this info final HiveAggregate newAggregate = (HiveAggregate) rel.copy(rel.getTraitSet(), ImmutableList.of(child)); newAggregate.setAggregateColumnsOrder(aggregateColumnsOrder); return newAggregate; }
Aggregate newAggregate = new HiveAggregate(aggregate.getCluster(), aggregate.getTraitSet(), relBuilder.build(), aggregate.getGroupSet(), null, aggregate.getAggCallList()); return newAggregate;
aggregate.getTraitSet(), relBuilder.build(), false, ImmutableBitSet.of(bottomGroupSet), null, bottomAggregateCalls)); aggregate.copy(aggregate.getTraitSet(), relBuilder.build(), aggregate.indicator, ImmutableBitSet.of(topGroupSet), null, topAggregateCalls));
@Override public boolean matches(RelOptRuleCall call) { final Filter filter = call.rel(0); final Aggregate aggregate = call.rel(1); return filter.getTraitSet().getTrait(ConventionTraitDef.INSTANCE) == aggregate.getTraitSet().getTrait(ConventionTraitDef.INSTANCE); }
public void onMatch(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final DruidQuery query = call.rel(1); if (!DruidQuery.isValidSignature(query.signature() + 'a')) { return; } if (aggregate.indicator || aggregate.getGroupSets().size() != 1 || BAD_AGG.apply(ImmutableTriple.of(aggregate, (RelNode) aggregate, query)) || !validAggregate(aggregate, query)) { return; } final RelNode newAggregate = aggregate.copy(aggregate.getTraitSet(), ImmutableList.of(Util.last(query.rels))); call.transformTo(DruidQuery.extendQuery(query, newAggregate)); }
public RelNode convert(RelNode rel) { final Aggregate agg = (Aggregate) rel; if (agg.getGroupSets().size() != 1) { // GROUPING SETS not supported; see // [CALCITE-734] Push GROUPING SETS to underlying SQL via JDBC adapter return null; } final RelTraitSet traitSet = agg.getTraitSet().replace(out); try { return new JdbcAggregate(rel.getCluster(), traitSet, convert(agg.getInput(), out), agg.indicator, agg.getGroupSet(), agg.getGroupSets(), agg.getAggCallList()); } catch (InvalidRelException e) { LOGGER.debug(e.toString()); return null; } } }
public RelNode convert(RelNode rel) { final Aggregate agg = (Aggregate) rel; if (agg.getGroupSets().size() != 1) { // GROUPING SETS not supported; see // [CALCITE-734] Push GROUPING SETS to underlying SQL via JDBC adapter return null; } final RelTraitSet traitSet = agg.getTraitSet().replace(out); try { return new JdbcAggregate(rel.getCluster(), traitSet, convert(agg.getInput(), out), agg.indicator, agg.getGroupSet(), agg.getGroupSets(), agg.getAggCallList()); } catch (InvalidRelException e) { LOGGER.debug(e.toString()); return null; } } }
final int cardinality = aggregate.getGroupSet().cardinality(); relBuilder.push( aggregate.copy(aggregate.getTraitSet(), relBuilder.build(), aggregate.indicator, ImmutableBitSet.range(cardinality), null, newAggCalls));
public void onMatch(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final RelNode input = call.rel(1); // Distinct is "GROUP BY c1, c2" (where c1, c2 are a set of columns on // which the input is unique, i.e. contain a key) and has no aggregate // functions or the functions we enumerated. It can be removed. final RelNode newInput = convert(input, aggregate.getTraitSet().simplify()); // If aggregate was projecting a subset of columns, add a project for the // same effect. final RelBuilder relBuilder = call.builder(); relBuilder.push(newInput); List<Integer> projectIndices = new ArrayList<>(aggregate.getGroupSet().asList()); for (AggregateCall aggCall : aggregate.getAggCallList()) { projectIndices.addAll(aggCall.getArgList()); } relBuilder.project(relBuilder.fields(projectIndices)); // Create a project if some of the columns have become // NOT NULL due to aggregate functions are removed relBuilder.convert(aggregate.getRowType(), true); call.transformTo(relBuilder.build()); } }
return; rel = aggRel.copy(aggRel.getTraitSet(), ImmutableList.of(rel)); rel = builder.push(rel).filter(remainingConditions).build(); call.transformTo(rel);
public void onMatch(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final DruidQuery query = call.rel(1); final RelNode topDruidNode = query.getTopNode(); final Project project = topDruidNode instanceof Project ? (Project) topDruidNode : null; if (!DruidQuery.isValidSignature(query.signature() + 'a')) { return; } if (aggregate.indicator || aggregate.getGroupSets().size() != 1) { return; } if (DruidQuery .computeProjectGroupSet(project, aggregate.getGroupSet(), query.table.getRowType(), query) == null) { return; } final List<String> aggNames = Util .skip(aggregate.getRowType().getFieldNames(), aggregate.getGroupSet().cardinality()); if (DruidQuery.computeDruidJsonAgg(aggregate.getAggCallList(), aggNames, project, query) == null) { return; } final RelNode newAggregate = aggregate .copy(aggregate.getTraitSet(), ImmutableList.of(query.getTopNode())); call.transformTo(DruidQuery.extendQuery(query, newAggregate)); } }
public void onMatch(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final RelNode input = call.rel(1); if (!aggregate.getAggCallList().isEmpty() || aggregate.indicator) { return; } final RelMetadataQuery mq = call.getMetadataQuery(); if (!SqlFunctions.isTrue(mq.areColumnsUnique(input, aggregate.getGroupSet()))) { return; } // Distinct is "GROUP BY c1, c2" (where c1, c2 are a set of columns on // which the input is unique, i.e. contain a key) and has no aggregate // functions. It can be removed. final RelNode newInput = convert(input, aggregate.getTraitSet().simplify()); // If aggregate was projecting a subset of columns, add a project for the // same effect. final RelBuilder relBuilder = call.builder(); relBuilder.push(newInput); if (newInput.getRowType().getFieldCount() > aggregate.getRowType().getFieldCount()) { relBuilder.project(relBuilder.fields(aggregate.getGroupSet().asList())); } call.transformTo(relBuilder.build()); } }
public void onMatch(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final RelNode input = call.rel(1); if (!aggregate.getAggCallList().isEmpty() || aggregate.indicator) { return; } final RelMetadataQuery mq = call.getMetadataQuery(); if (!SqlFunctions.isTrue(mq.areColumnsUnique(input, aggregate.getGroupSet()))) { return; } // Distinct is "GROUP BY c1, c2" (where c1, c2 are a set of columns on // which the input is unique, i.e. contain a key) and has no aggregate // functions. It can be removed. final RelNode newInput = convert(input, aggregate.getTraitSet().simplify()); // If aggregate was projecting a subset of columns, add a project for the // same effect. final RelBuilder relBuilder = call.builder(); relBuilder.push(newInput); if (newInput.getRowType().getFieldCount() > aggregate.getRowType().getFieldCount()) { relBuilder.project(relBuilder.fields(aggregate.getGroupSet().asList())); } call.transformTo(relBuilder.build()); } }