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;
}
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);
}
Aggregations