private boolean isAggWithConstantGbyKeys(final Aggregate aggregate, RelOptRuleCall call) { final RexBuilder rexBuilder = aggregate.getCluster().getRexBuilder(); final RelMetadataQuery mq = call.getMetadataQuery(); final RelOptPredicateList predicates = mq.getPulledUpPredicates(aggregate.getInput()); if (predicates == null) { return false; } final NavigableMap<Integer, RexNode> map = new TreeMap<>(); for (int key : aggregate.getGroupSet()) { final RexInputRef ref = rexBuilder.makeInputRef(aggregate.getInput(), key); if (predicates.constantMap.containsKey(ref)) { map.put(key, predicates.constantMap.get(ref)); } } // None of the group expressions are constant. Nothing to do. if (map.isEmpty()) { return false; } final int groupCount = aggregate.getGroupCount(); if (groupCount == map.size()) { return true; } return false; }
aggregateCalls.add(aggCall); return new HiveAggregate(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION), aggregate.getInput(), groupSet, origGroupSets, aggregateCalls);
aggregateCalls.add(aggCall); return new HiveAggregate(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION), aggregate.getInput(), true, groupSet, origGroupSets, aggregateCalls);
final List<Pair<RexNode, String>> projects = new ArrayList<Pair<RexNode, String>>(); final RelNode child = aggregate.getInput(); final List<RelDataTypeField> childFields = child.getRowType().getFieldList();
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; }
final List<Integer> nullableArgs = new ArrayList<>(args.size()); for (int arg : args) { if (aggRel.getInput().getRowType().getFieldList().get(arg).getType().isNullable()) { nullableArgs.add(arg); final Aggregate newAggregate = aggRel.copy(aggRel.getTraitSet(), aggRel.getInput(), aggRel.indicator, aggRel.getGroupSet(), aggRel.getGroupSets(), newAggCalls);
final RelNode newRight = aggregate.getInput(); final RexNode newCondition = RelOptUtil.createEquiJoinCondition(left, joinInfo.leftKeys, newRight, if(aggregate.getInput() instanceof HepRelVertex && ((HepRelVertex)aggregate.getInput()).getCurrentRel() instanceof Join) { Join rightJoin = (Join)(((HepRelVertex)aggregate.getInput()).getCurrentRel()); List<RexNode> projects = new ArrayList<>(); for(int i=0; i<rightJoin.getRowType().getFieldCount(); i++){ semi = call.builder().push(left).push(topProject).semiJoin(newCondition).build(); } else { semi = call.builder().push(left).push(aggregate.getInput()).semiJoin(newCondition).build();
relBuilder.push(oldAggRel.getInput()); final List<RexNode> inputExprs = new ArrayList<>(relBuilder.fields());
private ImmutableBitSet generateGroupSetIfCardinalitySame(final Aggregate aggregate, final ImmutableBitSet originalGroupSet, final ImmutableBitSet fieldsUsed) { Pair<RelOptTable, List<Integer>> tabToOrgCol = HiveRelOptUtil.getColumnOriginSet(aggregate.getInput(), originalGroupSet); if(tabToOrgCol == null) {
aggregate.getInput(), aggregate.indicator, aggregate.getGroupSet(),
final RelNode input = aggregate.getInput();
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; }
final RelNode input = aggregate.getInput(); RelMetadataQuery mq = aggregate.getCluster().getMetadataQuery();
final RelNode input = agg.getInput(); final RelOptPredicateList inputInfo = mq.getPulledUpPredicates(input); final List<RexNode> aggPullUpPredicates = new ArrayList<>();
final RelNode input = agg.getInput(); final RelOptPredicateList inputInfo = mq.getPulledUpPredicates(input); final List<RexNode> aggPullUpPredicates = new ArrayList<>();
final int iAvgInput = oldCall.getArgList().get(0); final RelDataType sum0InputType = typeFactory.createTypeWithNullability( getFieldType(oldAggRel.getInput(), iAvgInput), true); final RelDataType sumReturnType = getSumReturnType( rexBuilder.getTypeFactory(), sum0InputType, oldCall.getType()); oldCall.filterArg, oldAggRel.getGroupCount(), oldAggRel.getInput(), null, null);
final int iAvgInput = oldCall.getArgList().get(0); final RelDataType avgInputType = typeFactory.createTypeWithNullability( getFieldType(oldAggRel.getInput(), iAvgInput), true); final RelDataType sumReturnType = getSumReturnType( rexBuilder.getTypeFactory(), avgInputType, oldCall.getType()); oldCall.filterArg, oldAggRel.getGroupCount(), oldAggRel.getInput(), null, null); oldCall.filterArg, oldAggRel.getGroupCount(), oldAggRel.getInput(), countRetType, null);
if(shouldTransform) { final RelBuilder relBuilder = call.builder(); RelNode newRightInput = relBuilder.project(relBuilder.push(rightAggregate.getInput()). fields(rightAggregate.getGroupSet().asList())).build(); RelNode newSemiJoin = call.builder().push(left).push(newRightInput)
List<RelDataType> oldArgTypes = SqlTypeUtil.projectTypes( oldAggRel.getInput().getRowType(), oldCall.getArgList()); return rexBuilder.addAggCall(oldCall, nGroups,
final MutableRel input = toMutable(aggregate.getInput()); return MutableAggregate.of(input, aggregate.indicator, aggregate.getGroupSet(), aggregate.getGroupSets(),