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; }
List<Pair<RexNode, String>> newChildExprs = new ArrayList<>(); for (int j = 0; j < refsIndex.cardinality(); j++ ) { int pos = refsIndex.nth(j); newChildExprs.add( Pair.<RexNode, String>of(rexBuilder.makeInputRef(input, pos),
int condPos = origColEqCondsPos.nth(i); RexNode leftKey = leftJoinKeys.get(condPos); RexNode rightKey = rightJoinKeys.get(condPos);
int condPos = origColEqCondsPos.nth(i); RexNode leftKey = leftJoinKeys.get(condPos); RexNode rightKey = rightJoinKeys.get(condPos);
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; }
List<Pair<RexNode, String>> newChildExprs = new ArrayList<>(); for (int j = 0; j < refsIndex.cardinality(); j++ ) { int pos = refsIndex.nth(j); newChildExprs.add( Pair.<RexNode, String>of(rexBuilder.makeInputRef(input, pos),
int orgCol = originalGroupSet.nth(i); if(fieldsUsed.get((orgCol)) || currentKey.get(backtrackedCol)) {
RexInputRef iRef = new RexInputRef(groupBy.getGroupSet().nth(pos), groupBy.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY)); b.add(iRef.accept(new RexVisitor(schema, false, root.getCluster().getRexBuilder()))); RexInputRef iRef = new RexInputRef(groupBy.getGroupSet().nth(pos), groupBy.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY)); b.add(iRef.accept(new RexVisitor(schema, false, root.getCluster().getRexBuilder())));
RexInputRef iRef = new RexInputRef(groupBy.getGroupSet().nth(pos), groupBy.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY)); b.add(iRef.accept(new RexVisitor(schema))); RexInputRef iRef = new RexInputRef(groupBy.getGroupSet().nth(pos), groupBy.getCluster().getTypeFactory().createSqlType(SqlTypeName.ANY)); b.add(iRef.accept(new RexVisitor(schema)));
@Override public Integer get(int index) { return nth(index); }
@Override public Integer get(int index) { return nth(index); }
Run(final List<Column> columns) { for (Ord<Column> column : Ord.zip(columns)) { if (column.e.ordinal != column.i) { throw new IllegalArgumentException(); } } this.columns = columns; this.singletonSpaces = new ArrayList<>(Collections.nCopies(columns.size(), null)); for (ImmutableBitSet ordinals : ImmutableBitSet.range(columns.size()).powerSet()) { final Space space = new Space(ordinals, toColumns(ordinals)); spaces.add(space); if (ordinals.cardinality() == 1) { singletonSpaces.set(ordinals.nth(0), space); } } }
Run(final List<Column> columns) { for (Ord<Column> column : Ord.zip(columns)) { if (column.e.ordinal != column.i) { throw new IllegalArgumentException(); } } this.columns = columns; this.singletonSpaces = new ArrayList<>(Collections.nCopies(columns.size(), null)); for (ImmutableBitSet ordinals : ImmutableBitSet.range(columns.size()).powerSet()) { final Space space = new Space(ordinals, toColumns(ordinals)); spaces.add(space); if (ordinals.cardinality() == 1) { singletonSpaces.set(ordinals.nth(0), space); } } }
ColRef column(int offset) { if (offset < aggregate.getGroupSet().cardinality()) { return h.column(aggregate.getGroupSet().nth(offset)); } return null; // an aggregate function; no direct mapping } };
public int getSourceOpt(int source) { assert aggregate.getIndicatorCount() == 0; if (source < aggregate.getGroupCount()) { int in = tileKey.dimensions.nth(source); return aggregate.getGroupSet().indexOf(in); } Lattice.Measure measure = measures.get(source - aggregate.getGroupCount()); int i = tileKey.measures.indexOf(measure); assert i >= 0; return tileKey.dimensions.cardinality() + i; } } .inverse()));
public int getSourceOpt(int source) { assert aggregate.getIndicatorCount() == 0; if (source < aggregate.getGroupCount()) { int in = tileKey.dimensions.nth(source); return aggregate.getGroupSet().indexOf(in); } Lattice.Measure measure = measures.get(source - aggregate.getGroupCount()); int i = tileKey.measures.indexOf(measure); assert i >= 0; return tileKey.dimensions.cardinality() + i; } } .inverse()));
@Test public void testNth() { assertThat(ImmutableBitSet.of(0, 2, 4).nth(0), equalTo(0)); assertThat(ImmutableBitSet.of(0, 2, 4).nth(1), equalTo(2)); assertThat(ImmutableBitSet.of(0, 2, 4).nth(2), equalTo(4)); assertThat(ImmutableBitSet.of(0, 2, 63).nth(2), equalTo(63)); assertThat(ImmutableBitSet.of(0, 2, 64).nth(2), equalTo(64)); assertThat(ImmutableBitSet.of(64).nth(0), equalTo(64)); assertThat(ImmutableBitSet.of(64, 65).nth(0), equalTo(64)); assertThat(ImmutableBitSet.of(64, 65).nth(1), equalTo(65)); assertThat(ImmutableBitSet.of(64, 128).nth(1), equalTo(128)); try { ImmutableBitSet.of().nth(0); fail("expected throw"); } catch (IndexOutOfBoundsException e) { ImmutableBitSet.of().nth(1); fail("expected throw"); } catch (IndexOutOfBoundsException e) { ImmutableBitSet.of(64).nth(1); fail("expected throw"); } catch (IndexOutOfBoundsException e) { ImmutableBitSet.of(64).nth(-1); fail("expected throw"); } catch (IndexOutOfBoundsException e) {
final RexInputRef inputRef = RexInputRef.of(rel.getGroupSet().nth(idx), input.getRowType().getFieldList()); final Set<RexNode> originalExprs = mq.getExpressionLineage(input, inputRef);
final RexInputRef inputRef = RexInputRef.of(rel.getGroupSet().nth(idx), input.getRowType().getFieldList()); final Set<RexNode> originalExprs = mq.getExpressionLineage(input, inputRef);
positionsReferenced.set(topAgg.getGroupSet().nth(idx));