Search in sources :

Example 61 with RelNode

use of org.apache.calcite.rel.RelNode in project hive by apache.

the class HiveJoin method getStreamingInput.

public RelNode getStreamingInput() {
    MapJoinStreamingRelation mapJoinStreamingSide = getStreamingSide();
    RelNode smallInput;
    if (mapJoinStreamingSide == MapJoinStreamingRelation.LEFT_RELATION) {
        smallInput = this.getRight();
    } else if (mapJoinStreamingSide == MapJoinStreamingRelation.RIGHT_RELATION) {
        smallInput = this.getLeft();
    } else {
        smallInput = null;
    }
    return smallInput;
}
Also used : RelNode(org.apache.calcite.rel.RelNode)

Example 62 with RelNode

use of org.apache.calcite.rel.RelNode in project hive by apache.

the class HiveMaterializedViewFilterScanRule method apply.

protected void apply(RelOptRuleCall call, Project project, Filter filter, TableScan scan) {
    RelOptPlanner planner = call.getPlanner();
    List<RelOptMaterialization> materializations = (planner instanceof VolcanoPlanner) ? ((VolcanoPlanner) planner).getMaterializations() : ImmutableList.<RelOptMaterialization>of();
    if (!materializations.isEmpty()) {
        RelNode root = project.copy(project.getTraitSet(), Collections.singletonList(filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan))));
        // Costing is done in transformTo(), so we call it repeatedly with all applicable
        // materialized views and cheapest one will be picked
        List<RelOptMaterialization> applicableMaterializations = VolcanoPlanner.getApplicableMaterializations(root, materializations);
        for (RelOptMaterialization materialization : applicableMaterializations) {
            List<RelNode> subs = new MaterializedViewSubstitutionVisitor(materialization.queryRel, root, relBuilderFactory).go(materialization.tableRel);
            for (RelNode s : subs) {
                call.transformTo(s);
            }
        }
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) RelOptMaterialization(org.apache.calcite.plan.RelOptMaterialization) VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner)

Example 63 with RelNode

use of org.apache.calcite.rel.RelNode in project hive by apache.

the class HiveFilterProjectTransposeRule method onMatch.

public void onMatch(RelOptRuleCall call) {
    final Filter filter = call.rel(0);
    final Project origproject = call.rel(1);
    RexNode filterCondToPushBelowProj = filter.getCondition();
    RexNode unPushedFilCondAboveProj = null;
    if (RexUtil.containsCorrelation(filterCondToPushBelowProj)) {
        // Correlate from being de-correlated.
        return;
    }
    if (RexOver.containsOver(origproject.getProjects(), null)) {
        RexNode origFilterCond = filterCondToPushBelowProj;
        filterCondToPushBelowProj = null;
        if (pushThroughWindowing) {
            Set<Integer> commonPartitionKeys = getCommonPartitionCols(origproject.getProjects());
            List<RexNode> newPartKeyFilConds = new ArrayList<RexNode>();
            List<RexNode> unpushedFilConds = new ArrayList<RexNode>();
            // from t1 where value < 10)t1)t2
            if (!commonPartitionKeys.isEmpty()) {
                for (RexNode ce : RelOptUtil.conjunctions(origFilterCond)) {
                    RexNode newCondition = RelOptUtil.pushPastProject(ce, origproject);
                    if (HiveCalciteUtil.isDeterministicFuncWithSingleInputRef(newCondition, commonPartitionKeys)) {
                        newPartKeyFilConds.add(newCondition);
                    } else {
                        unpushedFilConds.add(ce);
                    }
                }
                if (!newPartKeyFilConds.isEmpty()) {
                    filterCondToPushBelowProj = RexUtil.composeConjunction(filter.getCluster().getRexBuilder(), newPartKeyFilConds, true);
                }
                if (!unpushedFilConds.isEmpty()) {
                    unPushedFilCondAboveProj = RexUtil.composeConjunction(filter.getCluster().getRexBuilder(), unpushedFilConds, true);
                }
            }
        }
    }
    if (filterCondToPushBelowProj != null) {
        RelNode newProjRel = getNewProject(filterCondToPushBelowProj, unPushedFilCondAboveProj, origproject, filter.getCluster().getTypeFactory(), call.builder());
        call.transformTo(newProjRel);
    }
}
Also used : Project(org.apache.calcite.rel.core.Project) HiveProject(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject) RelNode(org.apache.calcite.rel.RelNode) Filter(org.apache.calcite.rel.core.Filter) ArrayList(java.util.ArrayList) RexNode(org.apache.calcite.rex.RexNode)

Example 64 with RelNode

use of org.apache.calcite.rel.RelNode in project hive by apache.

the class HiveFilterProjectTransposeRule method getNewProject.

private static RelNode getNewProject(RexNode filterCondToPushBelowProj, RexNode unPushedFilCondAboveProj, Project oldProj, RelDataTypeFactory typeFactory, RelBuilder relBuilder) {
    // convert the filter to one that references the child of the project
    RexNode newPushedCondition = RelOptUtil.pushPastProject(filterCondToPushBelowProj, oldProj);
    // other rewrites.
    if (RexUtil.isNullabilityCast(typeFactory, newPushedCondition)) {
        newPushedCondition = ((RexCall) newPushedCondition).getOperands().get(0);
    }
    RelNode newPushedFilterRel = relBuilder.push(oldProj.getInput()).filter(newPushedCondition).build();
    RelNode newProjRel = relBuilder.push(newPushedFilterRel).project(oldProj.getProjects(), oldProj.getRowType().getFieldNames()).build();
    if (unPushedFilCondAboveProj != null) {
        // other rewrites.
        if (RexUtil.isNullabilityCast(typeFactory, newPushedCondition)) {
            unPushedFilCondAboveProj = ((RexCall) unPushedFilCondAboveProj).getOperands().get(0);
        }
        newProjRel = relBuilder.push(newProjRel).filter(unPushedFilCondAboveProj).build();
    }
    return newProjRel;
}
Also used : RexCall(org.apache.calcite.rex.RexCall) RelNode(org.apache.calcite.rel.RelNode) RexNode(org.apache.calcite.rex.RexNode)

Example 65 with RelNode

use of org.apache.calcite.rel.RelNode in project hive by apache.

the class CalcitePlanner method genLogicalPlan.

/**
   * This method is useful if we want to obtain the logical plan after being parsed and
   * optimized by Calcite.
   *
   * @return the Calcite plan for the query, null if it could not be generated
   */
public RelNode genLogicalPlan(ASTNode ast) throws SemanticException {
    LOG.info("Starting generating logical plan");
    PreCboCtx cboCtx = new PreCboCtx();
    //change the location of position alias process here
    processPositionAlias(ast);
    if (!genResolvedParseTree(ast, cboCtx)) {
        return null;
    }
    ASTNode queryForCbo = ast;
    if (cboCtx.type == PreCboCtx.Type.CTAS || cboCtx.type == PreCboCtx.Type.VIEW) {
        // nodeOfInterest is the query
        queryForCbo = cboCtx.nodeOfInterest;
    }
    runCBO = canCBOHandleAst(queryForCbo, getQB(), cboCtx);
    if (!runCBO) {
        return null;
    }
    profilesCBO = obtainCBOProfiles(queryProperties);
    disableJoinMerge = true;
    final RelNode resPlan = logicalPlan();
    LOG.info("Finished generating logical plan");
    return resPlan;
}
Also used : HiveRelNode(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRelNode) RelNode(org.apache.calcite.rel.RelNode)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)219 RexNode (org.apache.calcite.rex.RexNode)75 ArrayList (java.util.ArrayList)50 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)30 RelDataType (org.apache.calcite.rel.type.RelDataType)27 RelTraitSet (org.apache.calcite.plan.RelTraitSet)25 HashMap (java.util.HashMap)24 RexBuilder (org.apache.calcite.rex.RexBuilder)24 RexInputRef (org.apache.calcite.rex.RexInputRef)21 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)20 Prel (org.apache.drill.exec.planner.physical.Prel)20 AggregateCall (org.apache.calcite.rel.core.AggregateCall)16 Pair (org.apache.calcite.util.Pair)16 ImmutableList (com.google.common.collect.ImmutableList)15 Project (org.apache.calcite.rel.core.Project)14 RelOptCluster (org.apache.calcite.plan.RelOptCluster)13 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)13 TreeMap (java.util.TreeMap)11 HashSet (java.util.HashSet)10 RelCollation (org.apache.calcite.rel.RelCollation)10