use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project drill by axbaretto.
the class TopProjectVisitor method addTopProjectPrel.
/**
* Adds top project to ensure final output field names are preserved.
* In case of duplicated column names, will rename duplicates.
* Top project will be added only if top project is non-trivial and
* child physical relational node is not project.
*
* @param prel physical relational node
* @param validatedRowType final output row type
* @return physical relational node with top project if necessary
*/
private Prel addTopProjectPrel(Prel prel, RelDataType validatedRowType) {
RelDataType rowType = prel.getRowType();
if (rowType.getFieldCount() != validatedRowType.getFieldCount()) {
return prel;
}
RexBuilder rexBuilder = prel.getCluster().getRexBuilder();
List<RexNode> projections = new ArrayList<>();
int projectCount = rowType.getFieldList().size();
for (int i = 0; i < projectCount; i++) {
projections.add(rexBuilder.makeInputRef(prel, i));
}
List<String> fieldNames = SqlValidatorUtil.uniquify(validatedRowType.getFieldNames(), SqlValidatorUtil.EXPR_SUGGESTER, prel.getCluster().getTypeFactory().getTypeSystem().isSchemaCaseSensitive());
RelDataType newRowType = RexUtil.createStructType(prel.getCluster().getTypeFactory(), projections, fieldNames, null);
ProjectPrel topProject = new ProjectPrel(prel.getCluster(), prel.getTraitSet(), prel, projections, newRowType, // outputProj = true : NONE -> OK_NEW_SCHEMA, also handle expression with NULL type.
true);
if (prel instanceof Project && DrillRelOptUtil.isTrivialProject(topProject, true)) {
return new ProjectPrel(prel.getCluster(), prel.getTraitSet(), ((Project) prel).getInput(), ((Project) prel).getProjects(), prel.getRowType(), // outputProj = true : NONE -> OK_NEW_SCHEMA, also handle expression with NULL type.
true);
} else {
return topProject;
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project drill by apache.
the class TopProjectVisitor method addTopProjectPrel.
/**
* Adds top project to ensure final output field names are preserved.
* In case of duplicated column names, will rename duplicates.
* Top project will be added only if top project is non-trivial and
* child physical relational node is not project.
*
* @param prel physical relational node
* @param validatedRowType final output row type
* @return physical relational node with top project if necessary
*/
private Prel addTopProjectPrel(Prel prel, RelDataType validatedRowType) {
RelDataType rowType = prel.getRowType();
if (rowType.getFieldCount() != validatedRowType.getFieldCount()) {
return prel;
}
RexBuilder rexBuilder = prel.getCluster().getRexBuilder();
List<RexNode> projections = new ArrayList<>();
int projectCount = rowType.getFieldList().size();
for (int i = 0; i < projectCount; i++) {
projections.add(rexBuilder.makeInputRef(prel, i));
}
List<String> fieldNames = SqlValidatorUtil.uniquify(validatedRowType.getFieldNames(), SqlValidatorUtil.EXPR_SUGGESTER, prel.getCluster().getTypeFactory().getTypeSystem().isSchemaCaseSensitive());
RelDataType newRowType = RexUtil.createStructType(prel.getCluster().getTypeFactory(), projections, fieldNames, null);
ProjectPrel topProject = new ProjectPrel(prel.getCluster(), prel.getTraitSet(), prel, projections, newRowType, // outputProj = true : NONE -> OK_NEW_SCHEMA, also handle expression with NULL type.
true);
if (prel instanceof Project && DrillRelOptUtil.isTrivialProject(topProject, true)) {
return new ProjectPrel(prel.getCluster(), prel.getTraitSet(), ((Project) prel).getInput(), ((Project) prel).getProjects(), prel.getRowType(), // outputProj = true : NONE -> OK_NEW_SCHEMA, also handle expression with NULL type.
true);
} else {
return topProject;
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project drill by apache.
the class DrillRelOptUtil method isProjectFlatten.
@SuppressWarnings("deprecation")
public static boolean isProjectFlatten(RelNode project) {
assert project instanceof Project : "Rel is NOT an instance of project!";
for (RexNode rex : project.getChildExps()) {
if (rex instanceof RexCall) {
RexCall function = (RexCall) rex;
String functionName = function.getOperator().getName();
if (functionName.equalsIgnoreCase("flatten")) {
return true;
}
}
}
return false;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project drill by apache.
the class DrillMergeProjectRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
Project topProject = call.rel(0);
Project bottomProject = call.rel(1);
// We have a complex output type do not fire the merge project rule
if (checkComplexOutput(topProject) || checkComplexOutput(bottomProject)) {
return false;
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project drill by apache.
the class DrillProjectRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final Project project = call.rel(0);
final RelNode input = project.getInput();
final RelTraitSet traits = project.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
final RelNode convertedInput = convert(input, input.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify());
call.transformTo(new DrillProjectRel(project.getCluster(), traits, convertedInput, project.getProjects(), project.getRowType()));
}
Aggregations