@Override public boolean matches(RelOptRuleCall call) { final Filter filterRel = call.rel(0); RexNode condition = filterRel.getCondition(); if (this.onlyDeterministic && !HiveCalciteUtil.isDeterministic(condition)) { return false; } return super.matches(call); }
/** Creates a MaterializedViewAggregateRule. */ protected MaterializedViewAggregateRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, String description, boolean generateUnionRewriting, HepProgram unionRewritingPullProgram) { super(operand, relBuilderFactory, description, generateUnionRewriting, unionRewritingPullProgram, false); this.filterProjectTransposeRule = new FilterProjectTransposeRule( Filter.class, Project.class, true, true, relBuilderFactory); this.filterAggregateTransposeRule = new FilterAggregateTransposeRule( Filter.class, relBuilderFactory, Aggregate.class); this.aggregateProjectPullUpConstantsRule = new AggregateProjectPullUpConstantsRule( Aggregate.class, Filter.class, relBuilderFactory, "AggFilterPullUpConstants"); this.projectMergeRule = new ProjectMergeRule(true, relBuilderFactory); }
/** * Creates a FilterProjectTransposeRule. * * <p>If {@code filterFactory} is null, creates the same kind of filter as * matched in the rule. Similarly {@code projectFactory}.</p> */ public FilterProjectTransposeRule( Class<? extends Filter> filterClass, Class<? extends Project> projectClass, boolean copyFilter, boolean copyProject, RelBuilderFactory relBuilderFactory) { this( operand(filterClass, operand(projectClass, any())), copyFilter, copyProject, relBuilderFactory); }
/** * Creates a FilterProjectTransposeRule. * * <p>If {@code copyFilter} is true, creates the same kind of Filter as * matched in the rule, otherwise it creates a Filter using the RelBuilder * obtained by the {@code relBuilderFactory}. * Similarly for {@code copyProject}. * * <p>Defining predicates for the Filter (using {@code filterPredicate}) * and/or the Project (using {@code projectPredicate} allows making the rule * more restrictive. */ public <F extends Filter, P extends Project> FilterProjectTransposeRule( Class<F> filterClass, Predicate<? super F> filterPredicate, Class<P> projectClass, Predicate<? super P> projectPredicate, boolean copyFilter, boolean copyProject, RelBuilderFactory relBuilderFactory) { this( operandJ(filterClass, null, filterPredicate, operandJ(projectClass, null, projectPredicate, any())), copyFilter, copyProject, relBuilderFactory); }
/** Creates a MaterializedViewAggregateRule. */ protected MaterializedViewAggregateRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, String description, boolean generateUnionRewriting, HepProgram unionRewritingPullProgram) { super(operand, relBuilderFactory, description, generateUnionRewriting, unionRewritingPullProgram, false); this.filterProjectTransposeRule = new FilterProjectTransposeRule( Filter.class, Project.class, true, true, relBuilderFactory); this.filterAggregateTransposeRule = new FilterAggregateTransposeRule( Filter.class, relBuilderFactory, Aggregate.class); this.aggregateProjectPullUpConstantsRule = new AggregateProjectPullUpConstantsRule( Aggregate.class, Filter.class, relBuilderFactory, "AggFilterPullUpConstants"); this.projectMergeRule = new ProjectMergeRule(true, relBuilderFactory); }
new FilterProjectTransposeRule(Filter.class, HiveFilter.DEFAULT_FILTER_FACTORY, HiveProject.class, HiveProject.DEFAULT_PROJECT_FACTORY));
@Override public boolean matches(RelOptRuleCall call) { final Filter filterRel = call.rel(0); // The condition fetched here can reference a udf that is not deterministic, but defined // as part of the select list when a view is in play. But the condition after the pushdown // will resolve to using the udf from select list. The check here for deterministic filters // should be based on the resolved expression. Refer to test case cbo_ppd_non_deterministic.q. RexNode condition = RelOptUtil.pushPastProject(filterRel.getCondition(), call.rel(1)); if (this.onlyDeterministic && !HiveCalciteUtil.isDeterministic(condition)) { return false; } return super.matches(call); }
/** Tests a variant of {@link FilterProjectTransposeRule} * that pushes a Filter that contains a correlating variable. */ @Test public void testFilterProjectTranspose() { final String sql = "SELECT e.empno\n" + "FROM emp as e\n" + "WHERE exists (\n" + " SELECT *\n" + " FROM (\n" + " SELECT deptno * 2 AS twiceDeptno\n" + " FROM dept) AS d\n" + " WHERE e.deptno = d.twiceDeptno)"; final FilterProjectTransposeRule filterProjectTransposeRule = new FilterProjectTransposeRule(Filter.class, filter -> true, Project.class, project -> true, true, true, RelFactories.LOGICAL_BUILDER); HepProgram program = new HepProgramBuilder() .addRuleInstance(filterProjectTransposeRule) .build(); sql(sql) .withDecorrelation(false) .expand(true) .with(program) .check(); }
@Override public boolean matches(RelOptRuleCall call) { final Filter filterRel = call.rel(0); RexNode condition = filterRel.getCondition(); if (!HiveCalciteUtil.isDeterministic(condition)) { return false; } return super.matches(call); } }
FilterJoinRule.TRUE_PREDICATE)) .addRuleInstance( new FilterProjectTransposeRule(Filter.class, Project.class, true, true, f)) .addRuleInstance(new FilterCorrelateRule(f))
FilterJoinRule.TRUE_PREDICATE)) .addRuleInstance( new FilterProjectTransposeRule(Filter.class, Project.class, true, true, f)) .addRuleInstance(new FilterCorrelateRule(f))