Search in sources :

Example 21 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.

the class OptimizerTest method testOrElseXX.

@Test
public void testOrElseXX() {
    // x || x
    ParameterExpression x = Expressions.parameter(boolean.class, "x");
    assertEquals("{\n  return x;\n}\n", optimize(Expressions.orElse(x, x)));
}
Also used : ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Test(org.junit.Test)

Example 22 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.

the class OptimizerTest method testAssign2.

@Test
public void testAssign2() {
    // long x = 0;
    // final long y = System.currentTimeMillis();
    // if (System.currentTimeMillis() > 0) {
    // x = y;
    // }
    // 
    // Make sure we don't fold two calls to System.currentTimeMillis into one.
    final ParameterExpression x_ = Expressions.parameter(long.class, "x");
    final ParameterExpression y_ = Expressions.parameter(long.class, "y");
    final Method mT = Linq4j.getMethod("java.lang.System", "currentTimeMillis");
    final ConstantExpression zero = Expressions.constant(0L);
    assertThat(optimize(Expressions.block(Expressions.declare(0, x_, zero), Expressions.declare(Modifier.FINAL, y_, Expressions.call(mT)), Expressions.ifThen(Expressions.greaterThan(Expressions.call(mT), zero), Expressions.statement(Expressions.assign(x_, y_))))), equalTo("{\n" + "  long x = 0L;\n" + "  if (System.currentTimeMillis() > 0L) {\n" + "    x = System.currentTimeMillis();\n" + "  }\n" + "}\n"));
}
Also used : ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) ConstantExpression(org.apache.calcite.linq4j.tree.ConstantExpression) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 23 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.

the class OptimizerTest method testOptimizeTernaryAeqBAB.

@Test
public void testOptimizeTernaryAeqBAB() {
    // a == b ? a : b
    ParameterExpression a = Expressions.parameter(boolean.class, "a");
    ParameterExpression b = Expressions.parameter(boolean.class, "b");
    assertEquals("{\n  return b;\n}\n", optimize(Expressions.condition(Expressions.equal(a, b), a, b)));
}
Also used : ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Test(org.junit.Test)

Example 24 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.

the class OptimizerTest method testOptimizeTernaryAneqBBA.

@Test
public void testOptimizeTernaryAneqBBA() {
    // a != b ? b : a
    ParameterExpression a = Expressions.parameter(boolean.class, "a");
    ParameterExpression b = Expressions.parameter(boolean.class, "b");
    assertEquals("{\n  return b;\n}\n", optimize(Expressions.condition(Expressions.notEqual(a, b), b, a)));
}
Also used : ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Test(org.junit.Test)

Example 25 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.

the class OptimizerTest method testNotEqualBoolFalse.

@Test
public void testNotEqualBoolFalse() {
    // x != false
    ParameterExpression x = Expressions.parameter(boolean.class, "x");
    assertEquals("{\n  return x;\n}\n", optimize(Expressions.notEqual(x, FALSE)));
}
Also used : ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Test(org.junit.Test)

Aggregations

ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)83 Test (org.junit.Test)41 Expression (org.apache.calcite.linq4j.tree.Expression)38 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)32 ArrayList (java.util.ArrayList)12 RelDataType (org.apache.calcite.rel.type.RelDataType)12 Type (java.lang.reflect.Type)9 Function1 (org.apache.calcite.linq4j.function.Function1)8 MemberDeclaration (org.apache.calcite.linq4j.tree.MemberDeclaration)8 MethodCallExpression (org.apache.calcite.linq4j.tree.MethodCallExpression)8 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)6 FunctionExpression (org.apache.calcite.linq4j.tree.FunctionExpression)6 Method (java.lang.reflect.Method)5 List (java.util.List)5 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)5 BinaryExpression (org.apache.calcite.linq4j.tree.BinaryExpression)5 BlockStatement (org.apache.calcite.linq4j.tree.BlockStatement)5 ClassDeclaration (org.apache.calcite.linq4j.tree.ClassDeclaration)5 ConstantExpression (org.apache.calcite.linq4j.tree.ConstantExpression)5 RexNode (org.apache.calcite.rex.RexNode)5