Search in sources :

Example 1 with ProjectAllowDupPrel

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

the class StarColumnConverter method insertProjUnderScreenOrWriter.

// insert PUS or PUW: Project Under Screen/Writer, when necessary.
private Prel insertProjUnderScreenOrWriter(Prel prel, RelDataType origRowType, Prel child) {
    ProjectPrel proj = null;
    List<RelNode> children = Lists.newArrayList();
    List<RexNode> exprs = Lists.newArrayList();
    for (int i = 0; i < origRowType.getFieldCount(); i++) {
        RexNode expr = child.getCluster().getRexBuilder().makeInputRef(origRowType.getFieldList().get(i).getType(), i);
        exprs.add(expr);
    }
    RelDataType newRowType = RexUtil.createStructType(child.getCluster().getTypeFactory(), exprs, origRowType.getFieldNames());
    int fieldCount = prel.getRowType().isStruct() ? prel.getRowType().getFieldCount() : 1;
    // Insert PUS/PUW : remove the prefix and keep the original field name.
    if (fieldCount > 1) {
        // // no point in allowing duplicates if we only have one column
        proj = new ProjectAllowDupPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
    } else {
        proj = new ProjectPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
    }
    children.add(proj);
    return (Prel) prel.copy(prel.getTraitSet(), children);
}
Also used : ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) RelNode(org.apache.calcite.rel.RelNode) ProjectAllowDupPrel(org.apache.drill.exec.planner.physical.ProjectAllowDupPrel) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) Prel(org.apache.drill.exec.planner.physical.Prel) ProjectAllowDupPrel(org.apache.drill.exec.planner.physical.ProjectAllowDupPrel) ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) ScreenPrel(org.apache.drill.exec.planner.physical.ScreenPrel) WriterPrel(org.apache.drill.exec.planner.physical.WriterPrel)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RexNode (org.apache.calcite.rex.RexNode)1 Prel (org.apache.drill.exec.planner.physical.Prel)1 ProjectAllowDupPrel (org.apache.drill.exec.planner.physical.ProjectAllowDupPrel)1 ProjectPrel (org.apache.drill.exec.planner.physical.ProjectPrel)1 ScanPrel (org.apache.drill.exec.planner.physical.ScanPrel)1 ScreenPrel (org.apache.drill.exec.planner.physical.ScreenPrel)1 WriterPrel (org.apache.drill.exec.planner.physical.WriterPrel)1