use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.BlockBuilder in project calcite by apache.
the class ExpressionTest method testSubExpressionElimination.
/**
* Test for common sub-expression elimination.
*/
@Test
public void testSubExpressionElimination() {
final BlockBuilder builder = new BlockBuilder(true);
ParameterExpression x = Expressions.parameter(Object.class, "p");
Expression current4 = builder.append("current4", Expressions.convert_(x, Object[].class));
Expression v = builder.append("v", Expressions.convert_(Expressions.arrayIndex(current4, Expressions.constant(4)), Short.class));
Expression v0 = builder.append("v0", Expressions.convert_(v, Number.class));
Expression v1 = builder.append("v1", Expressions.convert_(Expressions.arrayIndex(current4, Expressions.constant(4)), Short.class));
Expression v2 = builder.append("v2", Expressions.convert_(v, Number.class));
Expression v3 = builder.append("v3", Expressions.convert_(Expressions.arrayIndex(current4, Expressions.constant(4)), Short.class));
Expression v4 = builder.append("v4", Expressions.convert_(v3, Number.class));
Expression v5 = builder.append("v5", Expressions.call(v4, "intValue"));
Expression v6 = builder.append("v6", Expressions.condition(Expressions.equal(v2, Expressions.constant(null)), Expressions.constant(null), Expressions.equal(v5, Expressions.constant(1997))));
builder.add(Expressions.return_(null, v6));
assertEquals("{\n" + " final Short v = (Short) ((Object[]) p)[4];\n" + " return (Number) v == null ? (Boolean) null : (" + "(Number) v).intValue() == 1997;\n" + "}\n", Expressions.toString(builder.toBlock()));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.BlockBuilder in project calcite by apache.
the class InlinerTest method testAssignInConditionMultipleUsage.
@Test
public void testAssignInConditionMultipleUsage() {
// int t;
// return (t = 1) != a ? t : c
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression t = Expressions.parameter(int.class, "t");
builder.add(Expressions.declare(0, t, null));
Expression v = builder.append("v", Expressions.makeTernary(ExpressionType.Conditional, Expressions.makeBinary(ExpressionType.NotEqual, Expressions.assign(t, Expressions.constant(1)), Expressions.parameter(int.class, "a")), t, Expressions.parameter(int.class, "c")));
builder.add(Expressions.return_(null, v));
assertEquals("{\n" + " int t;\n" + " return (t = 1) != a ? t : c;\n" + "}\n", Expressions.toString(builder.toBlock()));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.BlockBuilder in project calcite by apache.
the class InlinerTest method testAssignInConditionMultipleUsageNonOptimized.
@Test
public void testAssignInConditionMultipleUsageNonOptimized() {
// int t = 2;
// return (t = 1) != a ? 1 : c
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression t = Expressions.parameter(int.class, "t");
builder.add(Expressions.declare(0, t, TWO));
Expression v = builder.append("v", Expressions.makeTernary(ExpressionType.Conditional, Expressions.makeBinary(ExpressionType.NotEqual, Expressions.assign(t, Expressions.constant(1)), Expressions.parameter(int.class, "a")), t, Expressions.parameter(int.class, "c")));
builder.add(Expressions.return_(null, v));
assertEquals("{\n" + " int t = 2;\n" + " return (t = 1) != a ? t : c;\n" + "}\n", Expressions.toString(builder.toBlock()));
}
Aggregations