/** * Creates a CoerceInputsRule. * * @param consumerRelClass Class of RelNode that will consume the inputs * @param coerceNames If true, coerce names and types; if false, coerce * type only * @param relBuilderFactory Builder for relational expressions */ public CoerceInputsRule(Class<? extends RelNode> consumerRelClass, boolean coerceNames, RelBuilderFactory relBuilderFactory) { super( operand(consumerRelClass, any()), relBuilderFactory, "CoerceInputsRule:" + consumerRelClass.getName()); this.consumerRelClass = consumerRelClass; this.coerceNames = coerceNames; }
@Test public void testRuleClass() throws Exception { // Verify that an entire class of rules can be applied. HepProgramBuilder programBuilder = HepProgram.builder(); programBuilder.addRuleClass(CoerceInputsRule.class); HepPlanner planner = new HepPlanner( programBuilder.build()); planner.addRule( new CoerceInputsRule(LogicalUnion.class, false, RelFactories.LOGICAL_BUILDER)); planner.addRule( new CoerceInputsRule(LogicalIntersect.class, false, RelFactories.LOGICAL_BUILDER)); checkPlanning(planner, "(select name from dept union select ename from emp)" + " intersect (select fname from customer.contact)"); }
@Test public void testRuleClass() throws Exception { // Verify that an entire class of rules can be applied. HepProgramBuilder programBuilder = HepProgram.builder(); programBuilder.addRuleClass(CoerceInputsRule.class); HepPlanner planner = new HepPlanner( programBuilder.build()); planner.addRule( new CoerceInputsRule(LogicalUnion.class, false, RelFactories.LOGICAL_BUILDER)); planner.addRule( new CoerceInputsRule(LogicalIntersect.class, false, RelFactories.LOGICAL_BUILDER)); checkPlanning(planner, "(select name from dept union select ename from emp)" + " intersect (select fname from customer.contact)"); }
/** * Creates a CoerceInputsRule. * * @param consumerRelClass Class of RelNode that will consume the inputs * @param coerceNames If true, coerce names and types; if false, coerce * type only * @param relBuilderFactory Builder for relational expressions */ public CoerceInputsRule(Class<? extends RelNode> consumerRelClass, boolean coerceNames, RelBuilderFactory relBuilderFactory) { super( operand(consumerRelClass, any()), relBuilderFactory, "CoerceInputsRule:" + consumerRelClass.getName()); this.consumerRelClass = consumerRelClass; this.coerceNames = coerceNames; }
@Ignore // Calcite does not support INSERT yet @Test public void testReduceCastsNullable() throws Exception { HepProgram program = new HepProgramBuilder() // Simulate the way INSERT will insert casts to the target types .addRuleInstance( new CoerceInputsRule(LogicalTableModify.class, false, RelFactories.LOGICAL_BUILDER)) // Convert projects to calcs, merge two calcs, and then // reduce redundant casts in merged calc. .addRuleInstance(ProjectToCalcRule.INSTANCE) .addRuleInstance(CalcMergeRule.INSTANCE) .addRuleInstance(ReduceExpressionsRule.CALC_INSTANCE) .build(); checkPlanning(program, "insert into sales.depts(name) " + "select cast(gender as varchar(128)) from sales.emps"); }
@Ignore // Calcite does not support INSERT yet @Test public void testReduceCastsNullable() throws Exception { HepProgram program = new HepProgramBuilder() // Simulate the way INSERT will insert casts to the target types .addRuleInstance( new CoerceInputsRule(LogicalTableModify.class, false, RelFactories.LOGICAL_BUILDER)) // Convert projects to calcs, merge two calcs, and then // reduce redundant casts in merged calc. .addRuleInstance(ProjectToCalcRule.INSTANCE) .addRuleInstance(CalcMergeRule.INSTANCE) .addRuleInstance(ReduceExpressionsRule.CALC_INSTANCE) .build(); checkPlanning(program, "insert into sales.depts(name) " + "select cast(gender as varchar(128)) from sales.emps"); }