@Override public boolean apply(@Nullable Aggregate input) { return input.getGroupType() != Aggregate.Group.SIMPLE; } }, operand(RelNode.class, any())), "AggregateMultipleExpandRule");
@Override public boolean matches(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); // Rule cannot be applied if there are GroupingSets if (aggregate.getGroupType() != Group.SIMPLE) { return false; } return super.matches(call); }
if (a.getGroupType() != Group.SIMPLE) {
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; }
if (rel.getGroupType() != Aggregate.Group.SIMPLE) { throw new AssertionError(Bug.CALCITE_461_FIXED);
if(rightAggregate.getGroupType() != Aggregate.Group.SIMPLE) { return;
ASTBuilder b; boolean groupingSetsExpression = false; Group aggregateType = groupBy.getGroupType(); switch (aggregateType) { case SIMPLE:
/** * @see org.apache.calcite.util.Bug#CALCITE_461_FIXED */ public static boolean isSimple(Aggregate aggregate) { return aggregate.getGroupType() == Group.SIMPLE; }
/** * @see org.apache.calcite.util.Bug#CALCITE_461_FIXED */ public static boolean isSimple(Aggregate aggregate) { return aggregate.getGroupType() == Group.SIMPLE; }
@Override public boolean apply(@Nullable Aggregate input) { return input.getGroupType() != Aggregate.Group.SIMPLE; } }, operand(RelNode.class, any())), "AggregateMultipleExpandRule");
@Override protected boolean isValidPlan(Project topProject, RelNode node, RelMetadataQuery mq) { if (!(node instanceof Aggregate)) { return false; } Aggregate aggregate = (Aggregate) node; if (aggregate.getGroupType() != Aggregate.Group.SIMPLE) { // TODO: Rewriting with grouping sets not supported yet return false; } return isValidRelNodePlan(aggregate.getInput(), mq); }
@Override protected boolean isValidPlan(Project topProject, RelNode node, RelMetadataQuery mq) { if (!(node instanceof Aggregate)) { return false; } Aggregate aggregate = (Aggregate) node; if (aggregate.getGroupType() != Aggregate.Group.SIMPLE) { // TODO: Rewriting with grouping sets not supported yet return false; } return isValidRelNodePlan(aggregate.getInput(), mq); }
/** Creates an FlinkAggregateJoinTransposeRule. */ public FlinkAggregateJoinTransposeRule(Class<? extends Aggregate> aggregateClass, Class<? extends Join> joinClass, RelBuilderFactory relBuilderFactory, boolean allowFunctions, boolean allowLeftOrRightOuterJoin) { super( operandJ(aggregateClass, null, aggregate -> aggregate.getGroupType() == Aggregate.Group.SIMPLE, operand(joinClass, any())), relBuilderFactory, null); this.allowFunctions = allowFunctions; this.allowLeftOrRightOuterJoin = allowLeftOrRightOuterJoin; }
/** Creates an AggregateJoinTransposeRule. */ public AggregateJoinTransposeRule(Class<? extends Aggregate> aggregateClass, Class<? extends Join> joinClass, RelBuilderFactory relBuilderFactory, boolean allowFunctions) { super( operandJ(aggregateClass, null, aggregate -> aggregate.getGroupType() == Aggregate.Group.SIMPLE, operand(joinClass, any())), relBuilderFactory, null); this.allowFunctions = allowFunctions; }
/** Creates an AggregateJoinTransposeRule. */ public AggregateJoinTransposeRule(Class<? extends Aggregate> aggregateClass, Class<? extends Join> joinClass, RelBuilderFactory relBuilderFactory, boolean allowFunctions) { super( operandJ(aggregateClass, null, aggregate -> aggregate.getGroupType() == Aggregate.Group.SIMPLE, operand(joinClass, any())), relBuilderFactory, null); this.allowFunctions = allowFunctions; }
private boolean canPush(Aggregate aggregate, ImmutableBitSet rCols) { // If the filter references columns not in the group key, we cannot push final ImmutableBitSet groupKeys = ImmutableBitSet.range(0, aggregate.getGroupSet().cardinality()); if (!groupKeys.contains(rCols)) { return false; } if (aggregate.getGroupType() != Group.SIMPLE) { // If grouping sets are used, the filter can be pushed if // the columns referenced in the predicate are present in // all the grouping sets. for (ImmutableBitSet groupingSet : aggregate.getGroupSets()) { if (!groupingSet.contains(rCols)) { return false; } } } return true; } }
private boolean canPush(Aggregate aggregate, ImmutableBitSet rCols) { // If the filter references columns not in the group key, we cannot push final ImmutableBitSet groupKeys = ImmutableBitSet.range(0, aggregate.getGroupSet().cardinality()); if (!groupKeys.contains(rCols)) { return false; } if (aggregate.getGroupType() != Group.SIMPLE) { // If grouping sets are used, the filter can be pushed if // the columns referenced in the predicate are present in // all the grouping sets. for (ImmutableBitSet groupingSet : aggregate.getGroupSets()) { if (!groupingSet.contains(rCols)) { return false; } } } return true; } }
public RelWriter explainTerms(RelWriter pw) { // We skip the "groups" element if it is a singleton of "group". super.explainTerms(pw) .item("group", groupSet) .itemIf("groups", groupSets, getGroupType() != Group.SIMPLE) .itemIf("indicator", indicator, indicator) .itemIf("aggs", aggCalls, pw.nest()); if (!pw.nest()) { for (Ord<AggregateCall> ord : Ord.zip(aggCalls)) { pw.item(Util.first(ord.e.name, "agg#" + ord.i), ord.e); } } return pw; }
public RelWriter explainTerms(RelWriter pw) { // We skip the "groups" element if it is a singleton of "group". super.explainTerms(pw) .item("group", groupSet) .itemIf("groups", groupSets, getGroupType() != Group.SIMPLE) .itemIf("indicator", indicator, indicator) .itemIf("aggs", aggCalls, pw.nest()); if (!pw.nest()) { for (Ord<AggregateCall> ord : Ord.zip(aggCalls)) { pw.item(Util.first(ord.e.name, "agg#" + ord.i), ord.e); } } return pw; }
@Override public boolean matches(RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final RelNode input = call.rel(1); if (aggregate.getGroupCount() == 0 || aggregate.indicator || aggregate.getGroupType() != Aggregate.Group.SIMPLE) { return false; } for (AggregateCall aggCall : aggregate.getAggCallList()) { SqlKind aggCallKind = aggCall.getAggregation().getKind(); // TODO supports more AggregateCalls boolean isAllowAggCall = aggCallKind == SqlKind.SUM || aggCallKind == SqlKind.MIN || aggCallKind == SqlKind.MAX || aggCall.getAggregation() instanceof SqlAuxiliaryGroupAggFunction$; if (!isAllowAggCall || aggCall.filterArg >= 0 || aggCall.getArgList().size() != 1) { return false; } } final RelMetadataQuery mq = call.getMetadataQuery(); return SqlFunctions.isTrue(mq.areColumnsUnique(input, aggregate.getGroupSet())); }