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