use of org.apache.calcite.rel.rules.ReduceExpressionsRule in project calcite by apache.
the class RelOptRulesTest method testReduceConstantsRequiresExecutor.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-566">[CALCITE-566]
* ReduceExpressionsRule requires planner to have an Executor</a>.
*/
@Test
void testReduceConstantsRequiresExecutor() {
// Rule should not fire, but there should be no NPE
// Create a new planner instance, so we can remove its executor without
// breaking other tests.
final RelOptPlanner planner = new MockRelOptPlanner(Contexts.empty());
final String sql = "select * from (values (1,2)) where 1 + 2 > 3 + CAST(NULL AS INTEGER)";
sql(sql).withFactory(t -> t.withPlannerFactory(context -> planner)).withBefore((fixture, r) -> {
// Remove the executor
assertThat(r.getCluster().getPlanner(), sameInstance(planner));
r.getCluster().getPlanner().setExecutor(null);
return r;
}).withRule(CoreRules.FILTER_REDUCE_EXPRESSIONS).check();
}
use of org.apache.calcite.rel.rules.ReduceExpressionsRule in project calcite by apache.
the class RelOptRulesTest method checkDynamicFunctions.
RelOptFixture checkDynamicFunctions(boolean treatDynamicCallsAsConstant) {
// Create a customized executor with given context operator that reduces
// "USER" to "happyCalciteUser"
final RexExecutorImpl executor = new RexExecutorImpl(DataContexts.of(name -> name.equals(DataContext.Variable.USER.camelName) ? "happyCalciteUser" : fail("unknown: " + name)));
RelOptPlanner planner = new MockRelOptPlanner(Contexts.empty());
planner.setExecutor(executor);
final ReduceExpressionsRule<?> rule = CoreRules.PROJECT_REDUCE_EXPRESSIONS.config.withOperandFor(LogicalProject.class).withTreatDynamicCallsAsConstant(treatDynamicCallsAsConstant).as(ProjectReduceExpressionsRule.Config.class).toRule();
final String sql = "select USER from emp";
return sql(sql).withFactory(t -> t.withPlannerFactory(context -> planner)).withRule(rule);
}
Aggregations