Search in sources :

Example 1 with UnnestPrel

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

the class AdjustOperatorsSchemaVisitor method visitUnnest.

@Override
public Prel visitUnnest(UnnestPrel prel, Void value) throws RuntimeException {
    Preconditions.checkArgument(registeredPrel != null && registeredPrel instanceof LateralJoinPrel);
    Preconditions.checkArgument(prel.getRowType().getFieldCount() == 1);
    RexBuilder builder = prel.getCluster().getRexBuilder();
    LateralJoinPrel lateralJoinPrel = (LateralJoinPrel) getRegisteredPrel();
    int correlationIndex = lateralJoinPrel.getRequiredColumns().nextSetBit(0);
    String correlationColumnName = lateralJoinPrel.getLeft().getRowType().getFieldNames().get(correlationIndex);
    RexNode corrRef = builder.makeCorrel(lateralJoinPrel.getLeft().getRowType(), lateralJoinPrel.getCorrelationId());
    RexNode fieldAccess = builder.makeFieldAccess(corrRef, correlationColumnName, false);
    List<String> fieldNames = new ArrayList<>();
    List<RelDataType> fieldTypes = new ArrayList<>();
    for (RelDataTypeField field : prel.getRowType().getFieldList()) {
        fieldNames.add(correlationColumnName);
        fieldTypes.add(field.getType());
    }
    UnnestPrel unnestPrel = new UnnestPrel(prel.getCluster(), prel.getTraitSet(), prel.getCluster().getTypeFactory().createStructType(fieldTypes, fieldNames), fieldAccess);
    return unnestPrel;
}
Also used : LateralJoinPrel(org.apache.drill.exec.planner.physical.LateralJoinPrel) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) ArrayList(java.util.ArrayList) RexBuilder(org.apache.calcite.rex.RexBuilder) RelDataType(org.apache.calcite.rel.type.RelDataType) UnnestPrel(org.apache.drill.exec.planner.physical.UnnestPrel) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

ArrayList (java.util.ArrayList)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 RexNode (org.apache.calcite.rex.RexNode)1 LateralJoinPrel (org.apache.drill.exec.planner.physical.LateralJoinPrel)1 UnnestPrel (org.apache.drill.exec.planner.physical.UnnestPrel)1