Java Code Examples for org.apache.calcite.rel.core.SetOp#getInputs()
The following examples show how to use
org.apache.calcite.rel.core.SetOp#getInputs() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RelMdColumnOrigins.java From Bats with Apache License 2.0 | 5 votes |
public Set<RelColumnOrigin> getColumnOrigins(SetOp rel, RelMetadataQuery mq, int iOutputColumn) { final Set<RelColumnOrigin> set = new HashSet<>(); for (RelNode input : rel.getInputs()) { Set<RelColumnOrigin> inputSet = mq.getColumnOrigins(input, iOutputColumn); if (inputSet == null) { return null; } set.addAll(inputSet); } return set; }
Example 2
Source File: ProjectSetOpTransposeRule.java From Bats with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { LogicalProject origProj = call.rel(0); SetOp setOp = call.rel(1); // cannot push project past a distinct if (!setOp.all) { return; } // locate all fields referenced in the projection PushProjector pushProject = new PushProjector( origProj, null, setOp, preserveExprCondition, call.builder()); pushProject.locateAllRefs(); List<RelNode> newSetOpInputs = new ArrayList<>(); int[] adjustments = pushProject.getAdjustments(); // push the projects completely below the setop; this // is different from pushing below a join, where we decompose // to try to keep expensive expressions above the join, // because UNION ALL does not have any filtering effect, // and it is the only operator this rule currently acts on for (RelNode input : setOp.getInputs()) { // be lazy: produce two ProjectRels, and let another rule // merge them (could probably just clone origProj instead?) Project p = pushProject.createProjectRefsAndExprs(input, true, false); newSetOpInputs.add(pushProject.createNewProject(p, adjustments)); } // create a new setop whose children are the ProjectRels created above SetOp newSetOp = setOp.copy(setOp.getTraitSet(), newSetOpInputs); call.transformTo(newSetOp); }
Example 3
Source File: FilterSetOpTransposeRule.java From Bats with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { Filter filterRel = call.rel(0); SetOp setOp = call.rel(1); RexNode condition = filterRel.getCondition(); // create filters on top of each setop child, modifying the filter // condition to reference each setop child RexBuilder rexBuilder = filterRel.getCluster().getRexBuilder(); final RelBuilder relBuilder = call.builder(); List<RelDataTypeField> origFields = setOp.getRowType().getFieldList(); int[] adjustments = new int[origFields.size()]; final List<RelNode> newSetOpInputs = new ArrayList<>(); for (RelNode input : setOp.getInputs()) { RexNode newCondition = condition.accept( new RelOptUtil.RexInputConverter( rexBuilder, origFields, input.getRowType().getFieldList(), adjustments)); newSetOpInputs.add(relBuilder.push(input).filter(newCondition).build()); } // create a new setop whose children are the filters created above SetOp newSetOp = setOp.copy(setOp.getTraitSet(), newSetOpInputs); call.transformTo(newSetOp); }
Example 4
Source File: RelMdColumnOrigins.java From calcite with Apache License 2.0 | 5 votes |
public Set<RelColumnOrigin> getColumnOrigins(SetOp rel, RelMetadataQuery mq, int iOutputColumn) { final Set<RelColumnOrigin> set = new HashSet<>(); for (RelNode input : rel.getInputs()) { Set<RelColumnOrigin> inputSet = mq.getColumnOrigins(input, iOutputColumn); if (inputSet == null) { return null; } set.addAll(inputSet); } return set; }
Example 5
Source File: FilterSetOpTransposeRule.java From calcite with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { Filter filterRel = call.rel(0); SetOp setOp = call.rel(1); RexNode condition = filterRel.getCondition(); // create filters on top of each setop child, modifying the filter // condition to reference each setop child RexBuilder rexBuilder = filterRel.getCluster().getRexBuilder(); final RelBuilder relBuilder = call.builder(); List<RelDataTypeField> origFields = setOp.getRowType().getFieldList(); int[] adjustments = new int[origFields.size()]; final List<RelNode> newSetOpInputs = new ArrayList<>(); for (RelNode input : setOp.getInputs()) { RexNode newCondition = condition.accept( new RelOptUtil.RexInputConverter( rexBuilder, origFields, input.getRowType().getFieldList(), adjustments)); newSetOpInputs.add(relBuilder.push(input).filter(newCondition).build()); } // create a new setop whose children are the filters created above SetOp newSetOp = setOp.copy(setOp.getTraitSet(), newSetOpInputs); call.transformTo(newSetOp); }
Example 6
Source File: SubQueryDecorrelator.java From flink with Apache License 2.0 | 4 votes |
/** * check whether a SetOp has some children node which have correlation condition. * e.g. SELECT a FROM l WHERE b IN (SELECT r1.e FROM r1 WHERE l.a = r1.d UNION SELECT r2.i FROM r2) */ private void checkCorConditionOfSetOpInputs(SetOp setOp) { for (RelNode child : setOp.getInputs()) { checkCorConditionOfInput(child); } }
Example 7
Source File: SubQueryDecorrelator.java From flink with Apache License 2.0 | 4 votes |
/** * check whether a SetOp has some children node which have correlation condition. * e.g. SELECT a FROM l WHERE b IN (SELECT r1.e FROM r1 WHERE l.a = r1.d UNION SELECT r2.i FROM r2) */ private void checkCorConditionOfSetOpInputs(SetOp setOp) { for (RelNode child : setOp.getInputs()) { checkCorConditionOfInput(child); } }
Example 8
Source File: ProjectSetOpTransposeRule.java From calcite with Apache License 2.0 | 4 votes |
public void onMatch(RelOptRuleCall call) { LogicalProject origProj = call.rel(0); SetOp setOp = call.rel(1); // cannot push project past a distinct if (!setOp.all) { return; } // locate all fields referenced in the projection PushProjector pushProject = new PushProjector( origProj, null, setOp, preserveExprCondition, call.builder()); pushProject.locateAllRefs(); List<RelNode> newSetOpInputs = new ArrayList<>(); int[] adjustments = pushProject.getAdjustments(); final RelNode node; if (RexOver.containsOver(origProj.getProjects(), null)) { // should not push over past setop but can push its operand down. for (RelNode input : setOp.getInputs()) { Project p = pushProject.createProjectRefsAndExprs(input, true, false); // make sure that it is not a trivial project to avoid infinite loop. if (p.getRowType().equals(input.getRowType())) { return; } newSetOpInputs.add(p); } SetOp newSetOp = setOp.copy(setOp.getTraitSet(), newSetOpInputs); node = pushProject.createNewProject(newSetOp, adjustments); } else { // push some expressions below the setop; this // is different from pushing below a join, where we decompose // to try to keep expensive expressions above the join, // because UNION ALL does not have any filtering effect, // and it is the only operator this rule currently acts on setOp.getInputs().forEach(input -> newSetOpInputs.add( pushProject.createNewProject( pushProject.createProjectRefsAndExprs( input, true, false), adjustments))); node = setOp.copy(setOp.getTraitSet(), newSetOpInputs); } call.transformTo(node); }