use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class IndexPlanUtils method buildCollationNonCoveringIndexScan.
public static RelCollation buildCollationNonCoveringIndexScan(IndexDescriptor indexDesc, RelDataType indexScanRowType, RelDataType restrictedScanRowType, IndexCallContext context) {
if (context.getSortExprs() == null) {
return RelCollations.of(RelCollations.EMPTY.getFieldCollations());
}
final List<RelDataTypeField> indexFields = indexScanRowType.getFieldList();
final List<RelDataTypeField> rsFields = restrictedScanRowType.getFieldList();
final Map<LogicalExpression, RelFieldCollation> collationMap = indexDesc.getCollationMap();
assert collationMap != null : "Invalid collation map for index";
List<RelFieldCollation> fieldCollations = Lists.newArrayList();
Map<Integer, RelFieldCollation> rsScanCollationMap = Maps.newTreeMap();
// restricted scan's row type.
for (int i = 0; i < indexScanRowType.getFieldCount(); i++) {
RelDataTypeField f1 = indexFields.get(i);
for (int j = 0; j < rsFields.size(); j++) {
RelDataTypeField f2 = rsFields.get(j);
if (f1.getName().equals(f2.getName())) {
FieldReference ref = FieldReference.getWithQuotedRef(f1.getName());
RelFieldCollation origCollation = collationMap.get(ref);
if (origCollation != null) {
RelFieldCollation fc = new RelFieldCollation(j, origCollation.direction, origCollation.nullDirection);
rsScanCollationMap.put(origCollation.getFieldIndex(), fc);
}
}
}
}
// should sort by the order of these fields in indexDesc
for (Map.Entry<Integer, RelFieldCollation> entry : rsScanCollationMap.entrySet()) {
RelFieldCollation fc = entry.getValue();
if (fc != null) {
fieldCollations.add(fc);
}
}
final RelCollation collation = RelCollations.of(fieldCollations);
return collation;
}
use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class DrillAggregateRel method implement.
@Override
public LogicalOperator implement(DrillImplementor implementor) {
GroupingAggregate.Builder builder = GroupingAggregate.builder();
builder.setInput(implementor.visitChild(this, 0, getInput()));
final List<String> childFields = getInput().getRowType().getFieldNames();
final List<String> fields = getRowType().getFieldNames();
for (int group : BitSets.toIter(groupSet)) {
FieldReference fr = new FieldReference(childFields.get(group), ExpressionPosition.UNKNOWN);
builder.addKey(fr, fr);
}
for (Ord<AggregateCall> aggCall : Ord.zip(aggCalls)) {
FieldReference ref = new FieldReference(fields.get(groupSet.cardinality() + aggCall.i));
LogicalExpression expr = toDrill(aggCall.e, childFields, implementor);
builder.addExpr(ref, expr);
}
return builder.build();
}
use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class AbstractIndexPlanGenerator method createRangeDistRight.
// Range distribute the right side of the join, on row keys using a range partitioning function
protected RelNode createRangeDistRight(final RelNode rightPrel, final RelDataTypeField rightRowKeyField, final DbGroupScan origDbGroupScan) {
List<DrillDistributionTrait.DistributionField> rangeDistFields = Lists.newArrayList(new DrillDistributionTrait.DistributionField(0));
FieldReference rangeDistRef = FieldReference.getWithQuotedRef(rightRowKeyField.getName());
List<FieldReference> rangeDistRefList = Lists.newArrayList();
rangeDistRefList.add(rangeDistRef);
final DrillDistributionTrait distRight;
if (IndexPlanUtils.scanIsPartition(origDbGroupScan)) {
distRight = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.RANGE_DISTRIBUTED, ImmutableList.copyOf(rangeDistFields), origDbGroupScan.getRangePartitionFunction(rangeDistRefList));
} else {
distRight = DrillDistributionTrait.SINGLETON;
}
RelTraitSet rightTraits = newTraitSet(distRight).plus(Prel.DRILL_PHYSICAL);
RelNode convertedRight = Prule.convert(rightPrel, rightTraits);
return convertedRight;
}
use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class DrillJoinRel method implement.
@Override
public LogicalOperator implement(DrillImplementor implementor) {
final List<String> fields = getRowType().getFieldNames();
assert isUnique(fields);
final int leftCount = left.getRowType().getFieldCount();
final List<String> leftFields = fields.subList(0, leftCount);
final List<String> rightFields = fields.subList(leftCount, fields.size());
final LogicalOperator leftOp = implementInput(implementor, 0, 0, left);
final LogicalOperator rightOp = implementInput(implementor, 1, leftCount, right);
Join.Builder builder = Join.builder();
builder.type(joinType);
builder.left(leftOp);
builder.right(rightOp);
for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
builder.addCondition(EQUALITY_CONDITION, new FieldReference(leftFields.get(pair.left)), new FieldReference(rightFields.get(pair.right)));
}
return builder.build();
}
use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class JoinPruleBase method createRangePartitionRightPlan.
protected void createRangePartitionRightPlan(RelOptRuleCall call, RowKeyJoinRel join, PhysicalJoinType physicalJoinType, boolean implementAsRowKeyJoin, RelNode left, RelNode right, RelCollation collationLeft, RelCollation collationRight) throws InvalidRelException {
assert join.getRightKeys().size() == 1 : "Cannot create range partition plan with multi-column join condition";
int joinKeyRight = join.getRightKeys().get(0);
List<DrillDistributionTrait.DistributionField> rangeDistFields = Lists.newArrayList(new DrillDistributionTrait.DistributionField(joinKeyRight));
List<FieldReference> rangeDistRefList = Lists.newArrayList();
FieldReference rangeDistRef = FieldReference.getWithQuotedRef(right.getRowType().getFieldList().get(joinKeyRight).getName());
rangeDistRefList.add(rangeDistRef);
RelNode leftScan = DrillPushRowKeyJoinToScanRule.getValidJoinInput(left);
DrillDistributionTrait rangePartRight = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.RANGE_DISTRIBUTED, ImmutableList.copyOf(rangeDistFields), ((DbGroupScan) ((DrillScanRelBase) leftScan).getGroupScan()).getRangePartitionFunction(rangeDistRefList));
RelTraitSet traitsLeft = null;
RelTraitSet traitsRight = null;
if (physicalJoinType == PhysicalJoinType.HASH_JOIN) {
traitsLeft = left.getTraitSet().plus(Prel.DRILL_PHYSICAL);
traitsRight = right.getTraitSet().plus(Prel.DRILL_PHYSICAL).plus(rangePartRight);
}
final RelNode convertedLeft = convert(left, traitsLeft);
final RelNode convertedRight = convert(right, traitsRight);
DrillJoinRelBase newJoin = null;
if (physicalJoinType == PhysicalJoinType.HASH_JOIN) {
if (implementAsRowKeyJoin) {
newJoin = new RowKeyJoinPrel(join.getCluster(), traitsLeft, convertedLeft, convertedRight, join.getCondition(), join.getJoinType(), join.isSemiJoin());
} else {
newJoin = new HashJoinPrel(join.getCluster(), traitsLeft, convertedLeft, convertedRight, join.getCondition(), join.getJoinType(), false, /* no swap */
null, /* no runtime filter */
true, /* useful for join-restricted scans */
JoinControl.DEFAULT, join.isSemiJoin());
}
}
if (newJoin != null) {
call.transformTo(newJoin);
}
}
Aggregations