Search in sources :

Example 81 with FieldReference

use of org.apache.drill.common.expression.FieldReference in project drill by apache.

the class UnnestRecordBatch method resetUnnestTransferPair.

private TransferPair resetUnnestTransferPair() {
    List<TransferPair> transfers = Lists.newArrayList();
    FieldReference fieldReference = new FieldReference(popConfig.getColumn());
    TransferPair transferPair = getUnnestFieldTransferPair(fieldReference);
    transfers.add(transferPair);
    logger.debug("Added transfer for unnest expression.");
    unnest.close();
    try {
        unnest.setup(context, incoming, this, transfers);
    } catch (SchemaChangeException e) {
        throw schemaChangeException(e, logger);
    }
    setUnnestVector();
    return transferPair;
}
Also used : TransferPair(org.apache.drill.exec.record.TransferPair) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) FieldReference(org.apache.drill.common.expression.FieldReference)

Example 82 with FieldReference

use of org.apache.drill.common.expression.FieldReference in project drill by apache.

the class DrillWindowRel method implement.

@Override
public LogicalOperator implement(DrillImplementor implementor) {
    final LogicalOperator inputOp = implementor.visitChild(this, 0, getInput());
    org.apache.drill.common.logical.data.Window.Builder builder = new org.apache.drill.common.logical.data.Window.Builder();
    final List<String> fields = getRowType().getFieldNames();
    final List<String> childFields = getInput().getRowType().getFieldNames();
    for (Group window : groups) {
        for (RelFieldCollation orderKey : window.orderKeys.getFieldCollations()) {
            builder.addOrdering(new Order.Ordering(orderKey.getDirection(), new FieldReference(fields.get(orderKey.getFieldIndex()))));
        }
        for (int group : BitSets.toIter(window.keys)) {
            FieldReference fr = new FieldReference(childFields.get(group), ExpressionPosition.UNKNOWN);
            builder.addWithin(fr, fr);
        }
        int groupCardinality = window.keys.cardinality();
        for (Ord<AggregateCall> aggCall : Ord.zip(window.getAggregateCalls(this))) {
            FieldReference ref = new FieldReference(fields.get(groupCardinality + aggCall.i));
            LogicalExpression expr = toDrill(aggCall.e, childFields);
            builder.addAggregation(ref, expr);
        }
    }
    builder.setInput(inputOp);
    org.apache.drill.common.logical.data.Window frame = builder.build();
    return frame;
}
Also used : Order(org.apache.drill.common.logical.data.Order) FieldReference(org.apache.drill.common.expression.FieldReference) LogicalOperator(org.apache.drill.common.logical.data.LogicalOperator) AggregateCall(org.apache.calcite.rel.core.AggregateCall) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation)

Example 83 with FieldReference

use of org.apache.drill.common.expression.FieldReference 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)

Example 84 with FieldReference

use of org.apache.drill.common.expression.FieldReference in project drill by apache.

the class InfoSchemaFilterBuilder method visitCastExpression.

@Override
public ExprNode visitCastExpression(CastExpression e, Void value) throws RuntimeException {
    if (e.getInput() instanceof FieldReference) {
        FieldReference fieldRef = (FieldReference) e.getInput();
        String field = fieldRef.getRootSegmentPath().toUpperCase();
        if (field.equals(CATS_COL_CATALOG_NAME) || field.equals(SCHS_COL_SCHEMA_NAME) || field.equals(SHRD_COL_TABLE_NAME) || field.equals(SHRD_COL_TABLE_SCHEMA) || field.equals(COLS_COL_COLUMN_NAME) || field.equals(FILES_COL_ROOT_SCHEMA_NAME) || field.equals(FILES_COL_WORKSPACE_NAME)) {
            return new FieldExprNode(field);
        }
    }
    return visitUnknown(e, value);
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) FieldExprNode(org.apache.drill.exec.store.ischema.InfoSchemaFilter.FieldExprNode) QuotedString(org.apache.drill.common.expression.ValueExpressions.QuotedString)

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