Java Code Examples for org.apache.calcite.rel.core.Filter#copy()
The following examples show how to use
org.apache.calcite.rel.core.Filter#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: MaterializedViewFilterScanRule.java From Bats with Apache License 2.0 | 6 votes |
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) { final RelOptPlanner planner = call.getPlanner(); final List<RelOptMaterialization> materializations = planner.getMaterializations(); if (!materializations.isEmpty()) { RelNode root = filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan)); List<RelOptMaterialization> applicableMaterializations = RelOptMaterializations.getApplicableMaterializations(root, materializations); for (RelOptMaterialization materialization : applicableMaterializations) { if (RelOptUtil.areRowTypesEqual(scan.getRowType(), materialization.queryRel.getRowType(), false)) { RelNode target = materialization.queryRel; final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext()); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); List<RelNode> subs = new MaterializedViewSubstitutionVisitor(target, root) .go(materialization.tableRel); for (RelNode s : subs) { call.transformTo(s); } } } } }
Example 2
Source File: DruidRules.java From calcite with Apache License 2.0 | 6 votes |
@Override public void onMatch(RelOptRuleCall call) { final Filter filter = call.rel(0); final DruidQuery query = call.rel(1); if (!DruidQuery.isValidSignature(query.signature() + 'h')) { return; } final RexNode cond = filter.getCondition(); final DruidJsonFilter druidJsonFilter = DruidJsonFilter .toDruidFilters(cond, query.getTopNode().getRowType(), query); if (druidJsonFilter != null) { final RelNode newFilter = filter .copy(filter.getTraitSet(), Util.last(query.rels), filter.getCondition()); final DruidQuery newDruidQuery = DruidQuery.extendQuery(query, newFilter); call.transformTo(newDruidQuery); } }
Example 3
Source File: MaterializedViewFilterScanRule.java From calcite with Apache License 2.0 | 6 votes |
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) { final RelOptPlanner planner = call.getPlanner(); final List<RelOptMaterialization> materializations = planner.getMaterializations(); if (!materializations.isEmpty()) { RelNode root = filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan)); List<RelOptMaterialization> applicableMaterializations = RelOptMaterializations.getApplicableMaterializations(root, materializations); for (RelOptMaterialization materialization : applicableMaterializations) { if (RelOptUtil.areRowTypesEqual(scan.getRowType(), materialization.queryRel.getRowType(), false)) { RelNode target = materialization.queryRel; final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext()); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); List<RelNode> subs = new SubstitutionVisitor(target, root) .go(materialization.tableRel); for (RelNode s : subs) { call.transformTo(s); } } } } }
Example 4
Source File: FilterProjectTransposeRule.java From Bats with Apache License 2.0 | 5 votes |
public void onMatch(RelOptRuleCall call) { final Filter filter = call.rel(0); final Project project = call.rel(1); if (RexOver.containsOver(project.getProjects(), null)) { // In general a filter cannot be pushed below a windowing calculation. // Applying the filter before the aggregation function changes // the results of the windowing invocation. // // When the filter is on the PARTITION BY expression of the OVER clause // it can be pushed down. For now we don't support this. return; } // convert the filter to one that references the child of the project RexNode newCondition = RelOptUtil.pushPastProject(filter.getCondition(), project); final RelBuilder relBuilder = call.builder(); RelNode newFilterRel; if (copyFilter) { newFilterRel = filter.copy(filter.getTraitSet(), project.getInput(), simplifyFilterCondition(newCondition, call)); } else { newFilterRel = relBuilder.push(project.getInput()).filter(newCondition).build(); } RelNode newProjRel = copyProject ? project.copy(project.getTraitSet(), newFilterRel, project.getProjects(), project.getRowType()) : relBuilder.push(newFilterRel) .project(project.getProjects(), project.getRowType().getFieldNames()) .build(); call.transformTo(newProjRel); }
Example 5
Source File: MaterializedViewFilterScanRule.java From quark with Apache License 2.0 | 5 votes |
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) { //Avoid optimizing already optimized scan if (scan instanceof QuarkViewScan || scan instanceof QuarkTileScan) { return; } RelNode root = filter.copy(filter.getTraitSet(), Collections.singletonList((RelNode) scan)); RelOptPlanner planner = call.getPlanner(); if (planner instanceof VolcanoPlanner) { List<RelOptMaterialization> materializations = ((VolcanoPlanner) planner).getMaterializations(); for (RelOptMaterialization materialization : materializations) { if (scan.getRowType().equals(materialization.queryRel.getRowType())) { RelNode target = materialization.queryRel; final HepPlanner hepPlanner = new HepPlanner(program, planner.getContext()); hepPlanner.setRoot(target); target = hepPlanner.findBestExp(); List<RelNode> subs = new MaterializedViewSubstitutionVisitor(target, root) .go(materialization.tableRel); for (RelNode s : subs) { call.transformTo(s); } } } } }
Example 6
Source File: FilterProjectTransposeRule.java From calcite with Apache License 2.0 | 4 votes |
public void onMatch(RelOptRuleCall call) { final Filter filter = call.rel(0); final Project project = call.rel(1); if (RexOver.containsOver(project.getProjects(), null)) { // In general a filter cannot be pushed below a windowing calculation. // Applying the filter before the aggregation function changes // the results of the windowing invocation. // // When the filter is on the PARTITION BY expression of the OVER clause // it can be pushed down. For now we don't support this. return; } // convert the filter to one that references the child of the project RexNode newCondition = RelOptUtil.pushPastProject(filter.getCondition(), project); final RelBuilder relBuilder = call.builder(); RelNode newFilterRel; if (copyFilter) { final RelNode input = project.getInput(); final RelTraitSet traitSet = filter.getTraitSet() .replaceIfs(RelCollationTraitDef.INSTANCE, () -> Collections.singletonList( input.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE))) .replaceIfs(RelDistributionTraitDef.INSTANCE, () -> Collections.singletonList( input.getTraitSet().getTrait(RelDistributionTraitDef.INSTANCE))); newCondition = RexUtil.removeNullabilityCast(relBuilder.getTypeFactory(), newCondition); newFilterRel = filter.copy(traitSet, input, newCondition); } else { newFilterRel = relBuilder.push(project.getInput()).filter(newCondition).build(); } RelNode newProjRel = copyProject ? project.copy(project.getTraitSet(), newFilterRel, project.getProjects(), project.getRowType()) : relBuilder.push(newFilterRel) .project(project.getProjects(), project.getRowType().getFieldNames()) .build(); call.transformTo(newProjRel); }