use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class InlinerTest method testInlineParameter.
@Test
public void testInlineParameter() {
ParameterExpression pe = Expressions.parameter(int.class, "p");
DeclarationStatement decl = Expressions.declare(16, "x", pe);
b.add(decl);
b.add(Expressions.return_(null, Expressions.add(decl.parameter, decl.parameter)));
assertEquals("{\n return p + p;\n}\n", b.toBlock().toString());
}
use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class Linq4jTest method testAsQueryable.
@Test
public void testAsQueryable() {
// "count" is an Enumerable method.
final int n = Linq4j.asEnumerable(emps).asQueryable().count();
assertEquals(4, n);
// "where" is a Queryable method
// first, use a lambda
ParameterExpression parameter = Expressions.parameter(Employee.class);
final Queryable<Employee> nh = Linq4j.asEnumerable(emps).asQueryable().where(Expressions.lambda(Predicate1.class, Expressions.equal(Expressions.field(parameter, Employee.class, "deptno"), Expressions.constant(10)), parameter));
assertEquals(3, nh.count());
// second, use an expression
final Queryable<Employee> nh2 = Linq4j.asEnumerable(emps).asQueryable().where(Expressions.lambda(new Predicate1<Employee>() {
public boolean apply(Employee v1) {
return v1.deptno == 10;
}
}));
assertEquals(3, nh2.count());
// use lambda, this time call whereN
ParameterExpression parameterE = Expressions.parameter(Employee.class);
ParameterExpression parameterN = Expressions.parameter(Integer.TYPE);
final Queryable<Employee> nh3 = Linq4j.asEnumerable(emps).asQueryable().whereN(Expressions.lambda(Predicate2.class, Expressions.andAlso(Expressions.equal(Expressions.field(parameterE, Employee.class, "deptno"), Expressions.constant(10)), Expressions.lessThan(parameterN, Expressions.constant(3))), parameterE, parameterN));
assertEquals(2, nh3.count());
}
use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class OptimizerTest method testAssign.
@Test
public void testAssign() {
// long x = 0;
// final long y = System.currentTimeMillis();
// if (System.nanoTime() > 0) {
// x = y;
// }
// System.out.println(x);
//
// In bug https://github.com/julianhyde/linq4j/issues/27, this was
// incorrectly optimized to
//
// if (System.nanoTime() > 0L) {
// System.currentTimeMillis();
// }
// System.out.println(0L);
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 Method mNano = Linq4j.getMethod("java.lang.System", "nanoTime");
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(mNano), zero), Expressions.statement(Expressions.assign(x_, y_))), Expressions.statement(Expressions.call(Expressions.field(null, System.class, "out"), "println", x_)))), equalTo("{\n" + " long x = 0L;\n" + " if (System.nanoTime() > 0L) {\n" + " x = System.currentTimeMillis();\n" + " }\n" + " System.out.println(x);\n" + "}\n"));
}
use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class OptimizerTest method testEqualPrimitiveNull.
@Test
public void testEqualPrimitiveNull() {
// (int) x == null
ParameterExpression x = Expressions.parameter(int.class, "x");
assertEquals("{\n return false;\n}\n", optimize(Expressions.equal(x, NULL)));
}
use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class OptimizerTest method testEqualSameExpr.
@Test
public void testEqualSameExpr() {
// x == x
ParameterExpression x = Expressions.parameter(int.class, "x");
assertEquals("{\n return true;\n}\n", optimize(Expressions.equal(x, x)));
}
Aggregations