Search in sources :

Example 71 with FieldReference

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;
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelCollation(org.apache.calcite.rel.RelCollation) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) Map(java.util.Map)

Example 72 with FieldReference

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();
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) FieldReference(org.apache.drill.common.expression.FieldReference) GroupingAggregate(org.apache.drill.common.logical.data.GroupingAggregate)

Example 73 with FieldReference

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;
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) RelNode(org.apache.calcite.rel.RelNode) RelTraitSet(org.apache.calcite.plan.RelTraitSet) DrillDistributionTrait(org.apache.drill.exec.planner.physical.DrillDistributionTrait)

Example 74 with FieldReference

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();
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) LogicalOperator(org.apache.drill.common.logical.data.LogicalOperator) Join(org.apache.drill.common.logical.data.Join)

Example 75 with FieldReference

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);
    }
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) RelTraitSet(org.apache.calcite.plan.RelTraitSet) DrillJoinRelBase(org.apache.drill.exec.planner.common.DrillJoinRelBase) RelNode(org.apache.calcite.rel.RelNode) DistributionField(org.apache.drill.exec.planner.physical.DrillDistributionTrait.DistributionField) DrillScanRelBase(org.apache.drill.exec.planner.common.DrillScanRelBase) DistributionField(org.apache.drill.exec.planner.physical.DrillDistributionTrait.DistributionField)

Aggregations

FieldReference (org.apache.drill.common.expression.FieldReference)84 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)38 Test (org.junit.Test)22 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)19 FunctionCall (org.apache.drill.common.expression.FunctionCall)16 SchemaPath (org.apache.drill.common.expression.SchemaPath)14 Ordering (org.apache.drill.common.logical.data.Order.Ordering)14 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)13 ArrayList (java.util.ArrayList)12 ValueExpressions (org.apache.drill.common.expression.ValueExpressions)12 MaterializedField (org.apache.drill.exec.record.MaterializedField)12 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)10 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)9 Order (org.apache.drill.common.logical.data.Order)9 ExecTest (org.apache.drill.exec.ExecTest)9 AggregateCall (org.apache.calcite.rel.core.AggregateCall)8 OperatorTest (org.apache.drill.categories.OperatorTest)8 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)8 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)7 VectorTest (org.apache.drill.categories.VectorTest)6