use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class OptimizerTest method testNotEqualPrimitiveNull.
@Test
public void testNotEqualPrimitiveNull() {
// (int) x == null
ParameterExpression x = Expressions.parameter(int.class, "x");
assertEquals("{\n return true;\n}\n", optimize(Expressions.notEqual(x, NULL)));
}
use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class OptimizerTest method testNotEqualBoolTrue.
@Test
public void testNotEqualBoolTrue() {
// x != true
ParameterExpression x = Expressions.parameter(boolean.class, "x");
assertEquals("{\n return !x;\n}\n", optimize(Expressions.notEqual(x, TRUE)));
}
use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class OptimizerTest method testNotEqualSameExpr.
@Test
public void testNotEqualSameExpr() {
// x != x
ParameterExpression x = Expressions.parameter(int.class, "x");
assertEquals("{\n return false;\n}\n", optimize(Expressions.notEqual(x, x)));
}
use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class OptimizerTest method testNotEqualObjectNull.
@Test
public void testNotEqualObjectNull() {
// (Integer) x == null
ParameterExpression x = Expressions.parameter(Integer.class, "x");
assertEquals("{\n return x != null;\n}\n", optimize(Expressions.notEqual(x, NULL)));
}
use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.
the class PhysTypeImpl method generateComparator.
public Expression generateComparator(RelCollation collation) {
// int c;
// c = Utilities.compare(v0, v1);
// if (c != 0) return c; // or -c if descending
// ...
// return 0;
BlockBuilder body = new BlockBuilder();
final Type javaRowClass = Primitive.box(this.javaRowClass);
final ParameterExpression parameterV0 = Expressions.parameter(javaRowClass, "v0");
final ParameterExpression parameterV1 = Expressions.parameter(javaRowClass, "v1");
final ParameterExpression parameterC = Expressions.parameter(int.class, "c");
final int mod = collation.getFieldCollations().size() == 1 ? Modifier.FINAL : 0;
body.add(Expressions.declare(mod, parameterC, null));
for (RelFieldCollation fieldCollation : collation.getFieldCollations()) {
final int index = fieldCollation.getFieldIndex();
Expression arg0 = fieldReference(parameterV0, index);
Expression arg1 = fieldReference(parameterV1, index);
switch(Primitive.flavor(fieldClass(index))) {
case OBJECT:
arg0 = Types.castIfNecessary(Comparable.class, arg0);
arg1 = Types.castIfNecessary(Comparable.class, arg1);
}
final boolean nullsFirst = fieldCollation.nullDirection == RelFieldCollation.NullDirection.FIRST;
final boolean descending = fieldCollation.getDirection() == RelFieldCollation.Direction.DESCENDING;
body.add(Expressions.statement(Expressions.assign(parameterC, Expressions.call(Utilities.class, fieldNullable(index) ? (nullsFirst != descending ? "compareNullsFirst" : "compareNullsLast") : "compare", arg0, arg1))));
body.add(Expressions.ifThen(Expressions.notEqual(parameterC, Expressions.constant(0)), Expressions.return_(null, descending ? Expressions.negate(parameterC) : parameterC)));
}
body.add(Expressions.return_(null, Expressions.constant(0)));
final List<MemberDeclaration> memberDeclarations = Expressions.<MemberDeclaration>list(Expressions.methodDecl(Modifier.PUBLIC, int.class, "compare", ImmutableList.of(parameterV0, parameterV1), body.toBlock()));
if (EnumerableRules.BRIDGE_METHODS) {
final ParameterExpression parameterO0 = Expressions.parameter(Object.class, "o0");
final ParameterExpression parameterO1 = Expressions.parameter(Object.class, "o1");
BlockBuilder bridgeBody = new BlockBuilder();
bridgeBody.add(Expressions.return_(null, Expressions.call(Expressions.parameter(Comparable.class, "this"), BuiltInMethod.COMPARATOR_COMPARE.method, Expressions.convert_(parameterO0, javaRowClass), Expressions.convert_(parameterO1, javaRowClass))));
memberDeclarations.add(overridingMethodDecl(BuiltInMethod.COMPARATOR_COMPARE.method, ImmutableList.of(parameterO0, parameterO1), bridgeBody.toBlock()));
}
return Expressions.new_(Comparator.class, Collections.<Expression>emptyList(), memberDeclarations);
}
Aggregations