@Deprecated // to be removed before 2.0 public static RexProgram normalize( RexBuilder rexBuilder, RexProgram program) { return program.normalize(rexBuilder, null); }
@Deprecated // to be removed before 2.0 public static RexProgram normalize( RexBuilder rexBuilder, RexProgram program) { return program.normalize(rexBuilder, null); }
@Deprecated // to be removed before 2.0 public RexProgram normalize(RexBuilder rexBuilder, boolean simplify) { final RelOptPredicateList predicates = RelOptPredicateList.EMPTY; return normalize(rexBuilder, simplify ? new RexSimplify(rexBuilder, predicates, RexUtil.EXECUTOR) : null); }
@Deprecated // to be removed before 2.0 public RexProgram normalize(RexBuilder rexBuilder, boolean simplify) { final RelOptPredicateList predicates = RelOptPredicateList.EMPTY; return normalize(rexBuilder, simplify ? new RexSimplify(rexBuilder, predicates, RexUtil.EXECUTOR) : null); }
protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet, RelBuilder relBuilder, RelNode input, RexProgram program) { assert !program.containsAggs(); program = program.normalize(cluster.getRexBuilder(), null); return super.makeRel(cluster, traitSet, relBuilder, input, program); } },
protected RelNode makeRel(RelOptCluster cluster, RelTraitSet traitSet, RelBuilder relBuilder, RelNode input, RexProgram program) { assert !program.containsAggs(); program = program.normalize(cluster.getRexBuilder(), null); return super.makeRel(cluster, traitSet, relBuilder, input, program); } },
/** * Returns whether this program is in canonical form. * * @param litmus What to do if an error is detected (program is not in * canonical form) * @param rexBuilder Rex builder * @return whether in canonical form */ public boolean isNormalized(Litmus litmus, RexBuilder rexBuilder) { final RexProgram normalizedProgram = normalize(rexBuilder, null); String normalized = normalizedProgram.toString(); String string = toString(); if (!normalized.equals(string)) { final String message = "Program is not normalized:\n" + "program: {}\n" + "normalized: {}\n"; return litmus.fail(message, string, normalized); } return litmus.succeed(); }
/** * Returns whether this program is in canonical form. * * @param litmus What to do if an error is detected (program is not in * canonical form) * @param rexBuilder Rex builder * @return whether in canonical form */ public boolean isNormalized(Litmus litmus, RexBuilder rexBuilder) { final RexProgram normalizedProgram = normalize(rexBuilder, null); String normalized = normalizedProgram.toString(); String string = toString(); if (!normalized.equals(string)) { final String message = "Program is not normalized:\n" + "program: {}\n" + "normalized: {}\n"; return litmus.fail(message, string, normalized); } return litmus.succeed(); }
/** * Tests how the condition is simplified. */ @Test public void testSimplifyCondition() { final RexProgram program = createProg(3).getProgram(false); assertThat(program.toString(), is("(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], " + "expr#4=[+($0, $1)], expr#5=[+($0, 1)], expr#6=[+($0, $t5)], " + "expr#7=[+($t4, $t2)], expr#8=[5], expr#9=[>($t2, $t8)], " + "expr#10=[true], expr#11=[IS NOT NULL($t5)], expr#12=[false], " + "expr#13=[null], expr#14=[CASE($t9, $t10, $t11, $t12, $t13)], " + "expr#15=[NOT($t14)], a=[$t7], b=[$t6], $condition=[$t15])")); assertThat(program.normalize(rexBuilder, simplify).toString(), is("(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], " + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], " + "expr#6=[+($t0, $t4)], expr#7=[5], expr#8=[>($t4, $t7)], " + "expr#9=[CAST($t8):BOOLEAN], expr#10=[IS FALSE($t9)], " + "a=[$t5], b=[$t6], $condition=[$t10])")); }
/** * Tests how the condition is simplified. */ @Test public void testSimplifyCondition() { final RexProgram program = createProg(3).getProgram(false); assertThat(program.toString(), is("(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], " + "expr#4=[+($0, $1)], expr#5=[+($0, 1)], expr#6=[+($0, $t5)], " + "expr#7=[+($t4, $t2)], expr#8=[5], expr#9=[>($t2, $t8)], " + "expr#10=[true], expr#11=[IS NOT NULL($t5)], expr#12=[false], " + "expr#13=[null], expr#14=[CASE($t9, $t10, $t11, $t12, $t13)], " + "expr#15=[NOT($t14)], a=[$t7], b=[$t6], $condition=[$t15])")); assertThat(program.normalize(rexBuilder, simplify).toString(), is("(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], " + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], " + "expr#6=[+($t0, $t4)], expr#7=[5], expr#8=[>($t4, $t7)], " + "expr#9=[NOT($t8)], " + "a=[$t5], b=[$t6], $condition=[$t9])")); }
/** * Tests how the condition is simplified. */ @Test public void testSimplifyCondition2() { final RexProgram program = createProg(4).getProgram(false); assertThat(program.toString(), is("(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], " + "expr#4=[+($0, $1)], expr#5=[+($0, 1)], expr#6=[+($0, $t5)], " + "expr#7=[+($t4, $t2)], expr#8=[5], expr#9=[>($t2, $t8)], " + "expr#10=[true], expr#11=[IS NOT NULL($t5)], expr#12=[false], " + "expr#13=[null], expr#14=[CASE($t9, $t10, $t11, $t12, $t13)], " + "expr#15=[NOT($t14)], expr#16=[IS TRUE($t15)], a=[$t7], b=[$t6], " + "$condition=[$t16])")); assertThat(program.normalize(rexBuilder, simplify).toString(), is("(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], " + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], " + "expr#6=[+($t0, $t4)], expr#7=[5], expr#8=[>($t4, $t7)], " + "expr#9=[CAST($t8):BOOLEAN], expr#10=[IS FALSE($t9)], " + "a=[$t5], b=[$t6], $condition=[$t10])")); }
/** * Tests how the condition is simplified. */ @Test public void testSimplifyCondition2() { final RexProgram program = createProg(4).getProgram(false); assertThat(program.toString(), is("(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], " + "expr#4=[+($0, $1)], expr#5=[+($0, 1)], expr#6=[+($0, $t5)], " + "expr#7=[+($t4, $t2)], expr#8=[5], expr#9=[>($t2, $t8)], " + "expr#10=[true], expr#11=[IS NOT NULL($t5)], expr#12=[false], " + "expr#13=[null], expr#14=[CASE($t9, $t10, $t11, $t12, $t13)], " + "expr#15=[NOT($t14)], expr#16=[IS TRUE($t15)], a=[$t7], b=[$t6], " + "$condition=[$t16])")); assertThat(program.normalize(rexBuilder, simplify).toString(), is("(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], " + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], " + "expr#6=[+($t0, $t4)], expr#7=[5], expr#8=[>($t4, $t7)], " + "expr#9=[NOT($t8)], " + "a=[$t5], b=[$t6], $condition=[$t9])")); }
/** * Tests construction of a RexProgram. */ @Test public void testBuildProgram() { final RexProgramBuilder builder = createProg(0); final RexProgram program = builder.getProgram(false); final String programString = program.toString(); TestUtil.assertEqualsVerbose( "(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], " + "expr#4=[+($0, $1)], expr#5=[+($0, $0)], expr#6=[+($t4, $t2)], " + "a=[$t6], b=[$t5])", programString); // Normalize the program using the RexProgramBuilder.normalize API. // Note that unused expression '77' is eliminated, input refs (e.g. $0) // become local refs (e.g. $t0), and constants are assigned to locals. final RexProgram normalizedProgram = program.normalize(rexBuilder, null); final String normalizedProgramString = normalizedProgram.toString(); TestUtil.assertEqualsVerbose( "(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], " + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], " + "expr#6=[+($t0, $t0)], a=[$t5], b=[$t6])", normalizedProgramString); }
/** * Tests construction of a RexProgram. */ @Test public void testBuildProgram() { final RexProgramBuilder builder = createProg(0); final RexProgram program = builder.getProgram(false); final String programString = program.toString(); TestUtil.assertEqualsVerbose( "(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], " + "expr#4=[+($0, $1)], expr#5=[+($0, $0)], expr#6=[+($t4, $t2)], " + "a=[$t6], b=[$t5])", programString); // Normalize the program using the RexProgramBuilder.normalize API. // Note that unused expression '77' is eliminated, input refs (e.g. $0) // become local refs (e.g. $t0), and constants are assigned to locals. final RexProgram normalizedProgram = program.normalize(rexBuilder, null); final String normalizedProgramString = normalizedProgram.toString(); TestUtil.assertEqualsVerbose( "(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], " + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], " + "expr#6=[+($t0, $t0)], a=[$t5], b=[$t6])", normalizedProgramString); }
final RexSimplify simplify = new RexSimplify(rexBuilder, predicates, RexUtil.EXECUTOR); final RexProgram program = this.program.normalize(rexBuilder, simplify);
final RexSimplify simplify = new RexSimplify(rexBuilder, predicates, RexUtil.EXECUTOR); final RexProgram program = this.program.normalize(rexBuilder, simplify);