use of org.apache.calcite.linq4j.tree.Expression in project calcite by apache.
the class OptimizerTest method testConditionalIfBoolFalseElse.
@Test
public void testConditionalIfBoolFalseElse() {
// if (bool) {return 1} else if (false) {return 2} else {return 3}
Expression bool = Expressions.parameter(boolean.class, "bool");
assertEquals("{\n" + " if (bool) {\n" + " return 1;\n" + " } else {\n" + " return 3;\n" + " }\n" + "}\n", optimize(Expressions.ifThenElse(bool, Expressions.return_(null, ONE), FALSE, Expressions.return_(null, TWO), Expressions.return_(null, THREE))));
}
use of org.apache.calcite.linq4j.tree.Expression in project samza by apache.
the class SamzaSqlScalarFunctionImpl method getImplementor.
@Override
public CallImplementor getImplementor() {
return RexImpTable.createImplementor((translator, call, translatedOperands) -> {
final Expression sqlContext = Expressions.parameter(SamzaSqlExecutionContext.class, "sqlContext");
final Expression samzaContext = Expressions.parameter(SamzaSqlExecutionContext.class, "context");
final Expression getUdfInstance = Expressions.call(ScalarUdf.class, sqlContext, getUdfMethod, Expressions.constant(udfMethod.getDeclaringClass().getName()), Expressions.constant(udfName), samzaContext);
List<Expression> convertedOperands = new ArrayList<>();
// We explicitly Convert the untyped arguments to type that the UDf expects.
for (int index = 0; index < translatedOperands.size(); index++) {
if (!udfMetadata.isDisableArgCheck() && translatedOperands.get(index).type == Object.class && udfMethod.getParameters()[index].getType() != Object.class) {
convertedOperands.add(Expressions.convert_(translatedOperands.get(index), udfMethod.getParameters()[index].getType()));
} else {
convertedOperands.add(translatedOperands.get(index));
}
}
final Expression callExpression = Expressions.call(Expressions.convert_(getUdfInstance, udfMethod.getDeclaringClass()), udfMethod, convertedOperands);
return callExpression;
}, NullPolicy.NONE, false);
}
Aggregations