Search in sources :

Example 1 with NamedDistributionField

use of org.apache.drill.exec.planner.physical.DrillDistributionTrait.NamedDistributionField in project drill by apache.

the class MetadataAggPrule method getDistributionFields.

/**
 * Returns list with named distribution fields which correspond to specified expressions arguments.
 *
 * @param namedExpressions expressions list
 * @return list of {@link NamedDistributionField} instances
 */
private static List<NamedDistributionField> getDistributionFields(List<NamedExpression> namedExpressions) {
    List<NamedDistributionField> distributionFields = new ArrayList<>();
    int groupByExprsSize = namedExpressions.size();
    for (int index = 0; index < groupByExprsSize; index++) {
        SchemaPath fieldPath = getArgumentReference(namedExpressions.get(index));
        NamedDistributionField field = new NamedDistributionField(index + 1, fieldPath.getRootSegmentPath());
        distributionFields.add(field);
    }
    return distributionFields;
}
Also used : NamedDistributionField(org.apache.drill.exec.planner.physical.DrillDistributionTrait.NamedDistributionField) SchemaPath(org.apache.drill.common.expression.SchemaPath) ArrayList(java.util.ArrayList)

Example 2 with NamedDistributionField

use of org.apache.drill.exec.planner.physical.DrillDistributionTrait.NamedDistributionField in project drill by apache.

the class HashPrelUtil method getHashExpression.

/**
 * Create a distribution hash expression.
 *
 * @param fields Distribution fields
 * @param rowType Row type
 * @return distribution hash expression
 */
public static LogicalExpression getHashExpression(List<DistributionField> fields, RelDataType rowType) {
    assert fields.size() > 0;
    List<String> childFields = rowType.getFieldNames();
    // If we already included a field with hash - no need to calculate hash further down
    if (childFields.contains(HASH_EXPR_NAME)) {
        return new FieldReference(HASH_EXPR_NAME);
    }
    List<LogicalExpression> expressions = new ArrayList<>();
    for (DistributionField field : fields) {
        if (field instanceof NamedDistributionField) {
            NamedDistributionField namedDistributionField = (NamedDistributionField) field;
            expressions.add(new FieldReference(namedDistributionField.getFieldName(), ExpressionPosition.UNKNOWN));
        } else {
            expressions.add(new FieldReference(childFields.get(field.getFieldId()), ExpressionPosition.UNKNOWN));
        }
    }
    LogicalExpression distSeed = ValueExpressions.getInt(DIST_SEED);
    return createHashBasedPartitionExpression(expressions, distSeed, HASH_HELPER_LOGICAL_EXPRESSION);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) FieldReference(org.apache.drill.common.expression.FieldReference) NamedDistributionField(org.apache.drill.exec.planner.physical.DrillDistributionTrait.NamedDistributionField) ArrayList(java.util.ArrayList) DistributionField(org.apache.drill.exec.planner.physical.DrillDistributionTrait.DistributionField) NamedDistributionField(org.apache.drill.exec.planner.physical.DrillDistributionTrait.NamedDistributionField)

Aggregations

ArrayList (java.util.ArrayList)2 NamedDistributionField (org.apache.drill.exec.planner.physical.DrillDistributionTrait.NamedDistributionField)2 FieldReference (org.apache.drill.common.expression.FieldReference)1 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)1 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 DistributionField (org.apache.drill.exec.planner.physical.DrillDistributionTrait.DistributionField)1