Search in sources :

Example 26 with Project

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;
    }
}
Also used : ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) Project(org.apache.calcite.rel.core.Project) ArrayList(java.util.ArrayList) RexBuilder(org.apache.calcite.rex.RexBuilder) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Example 27 with Project

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;
    }
}
Also used : ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) Project(org.apache.calcite.rel.core.Project) ArrayList(java.util.ArrayList) RexBuilder(org.apache.calcite.rex.RexBuilder) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Example 28 with Project

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;
}
Also used : RexCall(org.apache.calcite.rex.RexCall) Project(org.apache.calcite.rel.core.Project) RexNode(org.apache.calcite.rex.RexNode)

Example 29 with Project

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;
}
Also used : Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject)

Example 30 with Project

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()));
}
Also used : Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) RelNode(org.apache.calcite.rel.RelNode) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Aggregations

Project (org.apache.calcite.rel.core.Project)143 RexNode (org.apache.calcite.rex.RexNode)77 RelNode (org.apache.calcite.rel.RelNode)71 ArrayList (java.util.ArrayList)51 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)35 RexBuilder (org.apache.calcite.rex.RexBuilder)28 RelDataType (org.apache.calcite.rel.type.RelDataType)26 Test (org.junit.Test)23 Aggregate (org.apache.calcite.rel.core.Aggregate)22 Filter (org.apache.calcite.rel.core.Filter)22 Join (org.apache.calcite.rel.core.Join)22 List (java.util.List)20 RexLiteral (org.apache.calcite.rex.RexLiteral)19 AggregateCall (org.apache.calcite.rel.core.AggregateCall)18 Sort (org.apache.calcite.rel.core.Sort)18 RelBuilder (org.apache.calcite.tools.RelBuilder)17 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)16 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)16 Collectors (java.util.stream.Collectors)15 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)15