Java Code Examples for org.apache.calcite.rel.core.Union#copy()
The following examples show how to use
org.apache.calcite.rel.core.Union#copy() .
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: SortUnionTransposeRule.java From Bats with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { final Sort sort = call.rel(0); final Union union = call.rel(1); List<RelNode> inputs = new ArrayList<>(); // Thus we use 'ret' as a flag to identify if we have finished pushing the // sort past a union. boolean ret = true; final RelMetadataQuery mq = call.getMetadataQuery(); for (RelNode input : union.getInputs()) { if (!RelMdUtil.checkInputForCollationAndLimit(mq, input, sort.getCollation(), sort.offset, sort.fetch)) { ret = false; Sort branchSort = sort.copy(sort.getTraitSet(), input, sort.getCollation(), sort.offset, sort.fetch); inputs.add(branchSort); } else { inputs.add(input); } } // there is nothing to change if (ret) { return; } // create new union and sort Union unionCopy = (Union) union .copy(union.getTraitSet(), inputs, union.all); Sort result = sort.copy(sort.getTraitSet(), unionCopy, sort.getCollation(), sort.offset, sort.fetch); call.transformTo(result); }
Example 2
Source File: SortUnionTransposeRule.java From calcite with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { final Sort sort = call.rel(0); final Union union = call.rel(1); List<RelNode> inputs = new ArrayList<>(); // Thus we use 'ret' as a flag to identify if we have finished pushing the // sort past a union. boolean ret = true; final RelMetadataQuery mq = call.getMetadataQuery(); for (RelNode input : union.getInputs()) { if (!RelMdUtil.checkInputForCollationAndLimit(mq, input, sort.getCollation(), sort.offset, sort.fetch)) { ret = false; Sort branchSort = sort.copy(sort.getTraitSet(), input, sort.getCollation(), sort.offset, sort.fetch); inputs.add(branchSort); } else { inputs.add(input); } } // there is nothing to change if (ret) { return; } // create new union and sort Union unionCopy = (Union) union .copy(union.getTraitSet(), inputs, union.all); Sort result = sort.copy(sort.getTraitSet(), unionCopy, sort.getCollation(), sort.offset, sort.fetch); call.transformTo(result); }
Example 3
Source File: JoinUnionTransposeRule.java From Bats with Apache License 2.0 | 4 votes |
public void onMatch(RelOptRuleCall call) { final Join join = call.rel(0); final Union unionRel; RelNode otherInput; boolean unionOnLeft; if (call.rel(1) instanceof Union) { unionRel = call.rel(1); otherInput = call.rel(2); unionOnLeft = true; } else { otherInput = call.rel(1); unionRel = call.rel(2); unionOnLeft = false; } if (!unionRel.all) { return; } if (!join.getVariablesSet().isEmpty()) { return; } // The UNION ALL cannot be on the null generating side // of an outer join (otherwise we might generate incorrect // rows for the other side for join keys which lack a match // in one or both branches of the union) if (unionOnLeft) { if (join.getJoinType().generatesNullsOnLeft()) { return; } } else { if (join.getJoinType().generatesNullsOnRight()) { return; } } List<RelNode> newUnionInputs = new ArrayList<>(); for (RelNode input : unionRel.getInputs()) { RelNode joinLeft; RelNode joinRight; if (unionOnLeft) { joinLeft = input; joinRight = otherInput; } else { joinLeft = otherInput; joinRight = input; } newUnionInputs.add( join.copy( join.getTraitSet(), join.getCondition(), joinLeft, joinRight, join.getJoinType(), join.isSemiJoinDone())); } final SetOp newUnionRel = unionRel.copy(unionRel.getTraitSet(), newUnionInputs, true); call.transformTo(newUnionRel); }
Example 4
Source File: JoinUnionTransposeRule.java From calcite with Apache License 2.0 | 4 votes |
public void onMatch(RelOptRuleCall call) { final Join join = call.rel(0); final Union unionRel; RelNode otherInput; boolean unionOnLeft; if (call.rel(1) instanceof Union) { unionRel = call.rel(1); otherInput = call.rel(2); unionOnLeft = true; } else { otherInput = call.rel(1); unionRel = call.rel(2); unionOnLeft = false; } if (!unionRel.all) { return; } if (!join.getVariablesSet().isEmpty()) { return; } // The UNION ALL cannot be on the null generating side // of an outer join (otherwise we might generate incorrect // rows for the other side for join keys which lack a match // in one or both branches of the union) if (unionOnLeft) { if (join.getJoinType().generatesNullsOnLeft()) { return; } } else { if (join.getJoinType().generatesNullsOnRight() || !join.getJoinType().projectsRight()) { return; } } List<RelNode> newUnionInputs = new ArrayList<>(); for (RelNode input : unionRel.getInputs()) { RelNode joinLeft; RelNode joinRight; if (unionOnLeft) { joinLeft = input; joinRight = otherInput; } else { joinLeft = otherInput; joinRight = input; } newUnionInputs.add( join.copy( join.getTraitSet(), join.getCondition(), joinLeft, joinRight, join.getJoinType(), join.isSemiJoinDone())); } final SetOp newUnionRel = unionRel.copy(unionRel.getTraitSet(), newUnionInputs, true); call.transformTo(newUnionRel); }