private Statistic buildStatistic() { if (stats != null || primaryKey == -1) { return stats; } Direction dir = primaryKeyMonotonicity == INCREASING ? ASCENDING : DESCENDING; RelFieldCollation collation = new RelFieldCollation(primaryKey, dir, NullDirection.UNSPECIFIED); return Statistics.of(fields.size(), ImmutableList.of(ImmutableBitSet.of(primaryKey)), ImmutableList.of(RelCollations.of(collation))); }
public ImmutableList<RelCollation> collations(HiveAggregate aggregate, RelMetadataQuery mq) { // Compute collations ImmutableList.Builder<RelFieldCollation> collationListBuilder = new ImmutableList.Builder<RelFieldCollation>(); for (int pos : aggregate.getGroupSet().asList()) { final RelFieldCollation fieldCollation = new RelFieldCollation(pos); collationListBuilder.add(fieldCollation); } // Return aggregate collations return ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationListBuilder.build()))); }
private List<RelFieldCollation> getFieldCollations(IndexDesc desc, Collection<IndexFieldDesc> descCollection) { List<RelFieldCollation> fieldCollations = new ArrayList<>(); int i = 0; for (IndexFieldDesc field : descCollection) { RelFieldCollation.Direction direction = (field.getSortOrder() == IndexFieldDesc.Order.Asc) ? RelFieldCollation.Direction.ASCENDING : (field.getSortOrder() == IndexFieldDesc.Order.Desc ? RelFieldCollation.Direction.DESCENDING : null); if (direction != null) { // assume null direction of NULLS UNSPECIFIED for now until MapR-DB adds that to the APIs RelFieldCollation.NullDirection nulldir = direction == RelFieldCollation.Direction.ASCENDING ? NullDirection.LAST : (direction == RelFieldCollation.Direction.DESCENDING ? NullDirection.FIRST : NullDirection.UNSPECIFIED); RelFieldCollation c = new RelFieldCollation(i++, direction, nulldir); fieldCollations.add(c); } else { // if the direction is not present for a field, no need to examine remaining fields break; } } return fieldCollations; }
getEquiJoinPredicateElements().get(i); for (int leftPos : joinLeafPredInfo.getProjsFromLeftPartOfJoinKeysInJoinSchema()) { final RelFieldCollation leftFieldCollation = new RelFieldCollation(leftPos); collationListBuilder.add(leftFieldCollation); leftCollationListBuilder.add(leftFieldCollation); final RelFieldCollation rightFieldCollation = new RelFieldCollation(rightPos); collationListBuilder.add(rightFieldCollation); rightCollationListBuilder.add(rightFieldCollation);
@Override public List<RelCollation> getCollationList() { ImmutableList.Builder<RelFieldCollation> collationList = new ImmutableList.Builder<RelFieldCollation>(); for (Order sortColumn : this.hiveTblMetadata.getSortCols()) { for (int i=0; i<this.hiveTblMetadata.getSd().getCols().size(); i++) { FieldSchema field = this.hiveTblMetadata.getSd().getCols().get(i); if (field.getName().equals(sortColumn.getCol())) { Direction direction; NullDirection nullDirection; if (sortColumn.getOrder() == BaseSemanticAnalyzer.HIVE_COLUMN_ORDER_ASC) { direction = Direction.ASCENDING; nullDirection = NullDirection.FIRST; } else { direction = Direction.DESCENDING; nullDirection = NullDirection.LAST; } collationList.add(new RelFieldCollation(i, direction, nullDirection)); break; } } } return new ImmutableList.Builder<RelCollation>() .add(RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationList.build()))) .build(); }
private static RelFieldCollation collation(RexNode node, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection, List<RexNode> extraNodes) { switch (node.getKind()) { case INPUT_REF: return new RelFieldCollation(((RexInputRef) node).getIndex(), direction, Util.first(nullDirection, direction.defaultNullDirection())); case DESCENDING: return collation(((RexCall) node).getOperands().get(0), RelFieldCollation.Direction.DESCENDING, nullDirection, extraNodes); case NULLS_FIRST: return collation(((RexCall) node).getOperands().get(0), direction, RelFieldCollation.NullDirection.FIRST, extraNodes); case NULLS_LAST: return collation(((RexCall) node).getOperands().get(0), direction, RelFieldCollation.NullDirection.LAST, extraNodes); default: final int fieldIndex = extraNodes.size(); extraNodes.add(node); return new RelFieldCollation(fieldIndex, direction, Util.first(nullDirection, direction.defaultNullDirection())); } }
propagateCollationsLeft.add(new RelFieldCollation(e.getKey())); propagateCollationsRight.add(new RelFieldCollation(refToRef.get(e.getKey()) - nLeftColumns)); } else { propagateCollationsLeft.add(new RelFieldCollation(refToRef.get(e.getKey()))); propagateCollationsRight.add(new RelFieldCollation(e.getKey() - nLeftColumns));
private static RelFieldCollation collation(RexNode node, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection, List<RexNode> extraNodes) { switch (node.getKind()) { case INPUT_REF: return new RelFieldCollation(((RexInputRef) node).getIndex(), direction, Util.first(nullDirection, direction.defaultNullDirection())); case DESCENDING: return collation(((RexCall) node).getOperands().get(0), RelFieldCollation.Direction.DESCENDING, nullDirection, extraNodes); case NULLS_FIRST: return collation(((RexCall) node).getOperands().get(0), direction, RelFieldCollation.NullDirection.FIRST, extraNodes); case NULLS_LAST: return collation(((RexCall) node).getOperands().get(0), direction, RelFieldCollation.NullDirection.LAST, extraNodes); default: final int fieldIndex = extraNodes.size(); extraNodes.add(node); return new RelFieldCollation(fieldIndex, direction, Util.first(nullDirection, direction.defaultNullDirection())); } }
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; }
propagateCollationsLeft.add(new RelFieldCollation(e.getKey())); propagateCollationsRight.add(new RelFieldCollation(refToRef.get(e.getKey()) - nLeftColumns)); } else { propagateCollationsLeft.add(new RelFieldCollation(refToRef.get(e.getKey()))); propagateCollationsRight.add(new RelFieldCollation(e.getKey() - nLeftColumns));
fieldCollations.add(new RelFieldCollation(m.get(fc.getFieldIndex()), fc.direction, fc.nullDirection));
public ImmutableList<RelCollation> collations(HiveAggregate aggregate, RelMetadataQuery mq) { // Compute collations ImmutableList.Builder<RelFieldCollation> collationListBuilder = new ImmutableList.Builder<RelFieldCollation>(); for (int pos : aggregate.getGroupSet().asList()) { final RelFieldCollation fieldCollation = new RelFieldCollation(pos); collationListBuilder.add(fieldCollation); } // Return aggregate collations return ImmutableList.of( RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationListBuilder.build()))); }
if (!joinKeyPositions.contains(pos)) { joinKeyPositions.add(pos); collationListBuilder.add(new RelFieldCollation(pos));
@Override public List<RelCollation> getCollationList() { ImmutableList.Builder<RelFieldCollation> collationList = new ImmutableList.Builder<RelFieldCollation>(); for (Order sortColumn : this.hiveTblMetadata.getSortCols()) { for (int i=0; i<this.hiveTblMetadata.getSd().getCols().size(); i++) { FieldSchema field = this.hiveTblMetadata.getSd().getCols().get(i); if (field.getName().equals(sortColumn.getCol())) { Direction direction; NullDirection nullDirection; if (sortColumn.getOrder() == BaseSemanticAnalyzer.HIVE_COLUMN_ORDER_ASC) { direction = Direction.ASCENDING; nullDirection = NullDirection.FIRST; } else { direction = Direction.DESCENDING; nullDirection = NullDirection.LAST; } collationList.add(new RelFieldCollation(i,direction,nullDirection)); break; } } } return new ImmutableList.Builder<RelCollation>() .add(RelCollationTraitDef.INSTANCE.canonize( new HiveRelCollation(collationList.build()))) .build(); }
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; }
fieldCollations.add(new RelFieldCollation(fieldIndex, order, nullOrder));
getEquiJoinPredicateElements().get(i); for (int leftPos : joinLeafPredInfo.getProjsFromLeftPartOfJoinKeysInJoinSchema()) { final RelFieldCollation leftFieldCollation = new RelFieldCollation(leftPos); collationListBuilder.add(leftFieldCollation); leftCollationListBuilder.add(leftFieldCollation); final RelFieldCollation rightFieldCollation = new RelFieldCollation(rightPos); collationListBuilder.add(rightFieldCollation); rightCollationListBuilder.add(rightFieldCollation);
if (!joinKeyPositions.contains(pos)) { joinKeyPositions.add(pos); collationListBuilder.add(new RelFieldCollation(pos));
fieldCollations.add(new RelFieldCollation(fieldIndex, order, nullOrder));
@Override public RelFieldCollation apply(Integer input) { return new RelFieldCollation(input); } }).toList()));