public RelNode align(Project rel, List<RelFieldCollation> collations) { // 1) We extract the collations indices boolean containsWindowing = false; for (RexNode childExp : rel.getChildExps()) { if (childExp instanceof RexOver) { // TODO: support propagation for partitioning/ordering in windowing containsWindowing = true; break; } } ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder(); if (!containsWindowing) { for (RelFieldCollation c : collations) { RexNode rexNode = rel.getChildExps().get(c.getFieldIndex()); if (rexNode instanceof RexInputRef) { int newIdx = ((RexInputRef) rexNode).getIndex(); propagateCollations.add(c.copy((newIdx))); } } } // 2) We propagate final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build()); // 3) Return new Project return rel.copy(rel.getTraitSet(), ImmutableList.of(child)); }
idxToConjuncts.remove(refToRef.get(c.getFieldIndex())); if (c.getFieldIndex() < nLeftColumns) { propagateCollationsLeft.add(c.copy(c.getFieldIndex())); propagateCollationsRight.add(c.copy(refToRef.get(c.getFieldIndex()) - nLeftColumns)); } else { propagateCollationsLeft.add(c.copy(refToRef.get(c.getFieldIndex()))); propagateCollationsRight.add(c.copy(c.getFieldIndex() - nLeftColumns));
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; }
idxToConjuncts.remove(refToRef.get(c.getFieldIndex())); if (c.getFieldIndex() < nLeftColumns) { propagateCollationsLeft.add(c.copy(c.getFieldIndex())); propagateCollationsRight.add(c.copy(refToRef.get(c.getFieldIndex()) - nLeftColumns)); } else { propagateCollationsLeft.add(c.copy(refToRef.get(c.getFieldIndex()))); propagateCollationsRight.add(c.copy(c.getFieldIndex() - nLeftColumns));
fieldCollations.add(fc.copy(target));
fieldCollations.add(fc.copy(target));
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; }
public RelNode align(Project rel, List<RelFieldCollation> collations) { // 1) We extract the collations indices boolean containsWindowing = false; for (RexNode childExp : rel.getChildExps()) { if (childExp instanceof RexOver) { // TODO: support propagation for partitioning/ordering in windowing containsWindowing = true; break; } } ImmutableList.Builder<RelFieldCollation> propagateCollations = ImmutableList.builder(); if (!containsWindowing) { for (RelFieldCollation c : collations) { RexNode rexNode = rel.getChildExps().get(c.getFieldIndex()); if (rexNode instanceof RexInputRef) { int newIdx = ((RexInputRef) rexNode).getIndex(); propagateCollations.add(c.copy((newIdx))); } } } // 2) We propagate final RelNode child = dispatchAlign(rel.getInput(), propagateCollations.build()); // 3) Return new Project return rel.copy(rel.getTraitSet(), ImmutableList.of(child)); }
/** * Returns a copy of this RelFieldCollation with the field index shifted * {@code offset} to the right. */ public RelFieldCollation shift(int offset) { return copy(fieldIndex + offset); }
/** * Returns a copy of this RelFieldCollation with the field index shifted * {@code offset} to the right. */ public RelFieldCollation shift(int offset) { return copy(fieldIndex + offset); }
/** * Applies a mapping to a field collation. * * <p>If the field is not mapped, returns null. * * @param mapping Mapping * @param fieldCollation Field collation * @return collation with mapping applied */ public static RelFieldCollation apply( Mappings.TargetMapping mapping, RelFieldCollation fieldCollation) { final int target = mapping.getTargetOpt(fieldCollation.getFieldIndex()); if (target < 0) { return null; } return fieldCollation.copy(target); }
/** * Applies a mapping to a field collation. * * <p>If the field is not mapped, returns null. * * @param mapping Mapping * @param fieldCollation Field collation * @return collation with mapping applied */ public static RelFieldCollation apply( Mappings.TargetMapping mapping, RelFieldCollation fieldCollation) { final int target = mapping.getTargetOpt(fieldCollation.getFieldIndex()); if (target < 0) { return null; } return fieldCollation.copy(target); }
fieldCollation.copy(target));
/** Creates a copy of this collation that changes the ordinals of input * fields. */ public static RelCollation permute(RelCollation collation, Map<Integer, Integer> mapping) { return of( Util.transform(collation.getFieldCollations(), fc -> fc.copy(mapping.get(fc.getFieldIndex())))); }
fieldCollation.copy(target));
continue loop; // cannot do this collation fieldCollations.add(ifc.copy(integers.iterator().next()));
continue loop; // cannot do this collation fieldCollations.add(ifc.copy(integers.iterator().next()));
/** Creates a copy of this collation that changes the ordinals of input * fields. */ public static RelCollation permute(RelCollation collation, Mappings.TargetMapping mapping) { return of( Util.transform(collation.getFieldCollations(), fc -> fc.copy(mapping.getTarget(fc.getFieldIndex())))); } }
for (RelFieldCollation fieldCollation : fieldCollations) { if(projFieldMapping.containsKey(fieldCollation.getFieldIndex())) { newFieldCollations.add(fieldCollation.copy(projFieldMapping.get(fieldCollation.getFieldIndex()))); } else { newFieldCollations.add(fieldCollation);
final int index = relFieldCollation.getFieldIndex(); orderKeys.add( relFieldCollation.copy( getAdjustedIndex(index, beReferred, windowInputColumn)));