private boolean isAggregateWithoutGbyKeys(final Aggregate agg) { return agg.getGroupCount() == 0 ? true : false; }
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; }
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; }
private AggregateCall createAggregateCallWithBinding( RelDataTypeFactory typeFactory, SqlAggFunction aggFunction, RelDataType operandType, Aggregate oldAggRel, AggregateCall oldCall, int argOrdinal) { final Aggregate.AggCallBinding binding = new Aggregate.AggCallBinding(typeFactory, aggFunction, ImmutableList.of(operandType), oldAggRel.getGroupCount(), oldCall.filterArg >= 0); return AggregateCall.create(aggFunction, oldCall.isDistinct(), oldCall.isApproximate(), ImmutableIntList.of(argOrdinal), oldCall.filterArg, aggFunction.inferReturnType(binding), null); }
RexNode condition = rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, originalInputRefs .get(originalInputRefs.size() - 1), rexBuilder.makeExactLiteral(new BigDecimal( getGroupingIdValue(list, sourceOfForCountDistinct, aggr.getGroupCount())))); if (list.size() == 1) { int pos = list.get(0);
final int fieldCount = aggregate.getGroupCount() + aggregate.getAggCallList().size(); if (fieldCount != aggregate.getRowType().getFieldCount()) { throw new ISE( ImmutableBitSet.range(aggregate.getGroupCount(), fieldCount) ); newAggregateCalls.add(aggregate.getAggCallList().get(i - aggregate.getGroupCount())); for (int i = 0; i < aggregate.getGroupCount(); i++) { fixUpProjects.add(rexBuilder.makeInputRef(newAggregate, i)); int j = aggregate.getGroupCount(); for (int i = aggregate.getGroupCount(); i < fieldCount; i++) { if (callsToKeep.get(i)) { fixUpProjects.add(rexBuilder.makeInputRef(newAggregate, j++));
final int groupingFields = aggregate.getGroupCount() + aggregate.getIndicatorCount(); Set<String> projectExprsDigest = new HashSet<String>(); Map<String, RexNode> windowingExprsDigestToNodes = new HashMap<String,RexNode>();
final List<AggregateCall> aggCalls = aggRel.getAggCallList(); final List<AggregateCall> newAggCalls = new ArrayList<>(aggCalls.size()); int nextIdx = aggRel.getGroupCount() + aggRel.getIndicatorCount(); for (int i = 0; i < aggCalls.size(); i++) { AggregateCall aggCall = aggCalls.get(i); call.transformTo(newAggregate); } else { final int offset = aggRel.getGroupCount() + aggRel.getIndicatorCount(); final List<RexNode> projList = Lists.newArrayList(); for (int i = 0; i < offset; ++i) {
List<RexNode> joinConjs = new ArrayList<>(); List<RexNode> filterConjs = new ArrayList<>(); int groupCount = agg.getGroupCount(); int totalCount = agg.getGroupCount() + agg.getAggCallList().size(); for (int leftPos = 0, rightPos = totalCount; leftPos < groupCount; leftPos++, rightPos++) {
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 List<AggregateCall> newCalls = new ArrayList<>(aggregate.getAggCallList().size()); final List<RexNode> newProjects = new ArrayList<>(project.getChildExps()); final List<RexNode> newCasts = new ArrayList<>(aggregate.getGroupCount() + aggregate.getAggCallList().size()); final RelDataTypeFactory typeFactory = aggregate.getCluster().getTypeFactory();
final int groupCount = oldAggRel.getGroupCount(); final int indicatorCount = oldAggRel.getIndicatorCount();
ImmutableBitSet.range(aggregate.getGroupCount()))) {
Map<AggregateCall, RexNode> aggCallMapping, List<RexNode> inputExprs) { final int nGroups = oldAggRel.getGroupCount(); final RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder(); final RelDataTypeFactory typeFactory = oldAggRel.getCluster().getTypeFactory(); oldCall.getArgList(), oldCall.filterArg, oldAggRel.getGroupCount(), oldAggRel.getInput(), null,
Map<AggregateCall, RexNode> aggCallMapping, List<RexNode> inputExprs) { final int nGroups = oldAggRel.getGroupCount(); final RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder(); final RelDataTypeFactory typeFactory = oldAggRel.getCluster().getTypeFactory(); oldCall.getArgList(), oldCall.filterArg, oldAggRel.getGroupCount(), oldAggRel.getInput(), null, oldCall.getArgList(), oldCall.filterArg, oldAggRel.getGroupCount(), oldAggRel.getInput(), countRetType,
ImmutableBitSet.range(rightAggregate.getGroupCount())); if(shouldTransform) { final RelBuilder relBuilder = call.builder();
final int nGroups = oldAggRel.getGroupCount(); List<RelDataType> oldArgTypes = SqlTypeUtil.projectTypes(
ImmutableBitSet.range(aggregate.getGroupCount()))) {
ImmutableBitSet.range(aggregate.getGroupCount()))) {
joinInfo.rightSet().cardinality() != right.getPartialDruidQuery().getAggregate().getGroupCount()) { return;