本文整理汇总了Java中org.apache.calcite.linq4j.tree.Expressions.parameter方法的典型用法代码示例。如果您正苦于以下问题:Java Expressions.parameter方法的具体用法?Java Expressions.parameter怎么用?Java Expressions.parameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.linq4j.tree.Expressions
的用法示例。
在下文中一共展示了Expressions.parameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAssignInConditionMultipleUsageNonOptimized
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@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()));
}
示例2: testCompile
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testCompile() throws NoSuchMethodException {
// Creating a parameter for the expression tree.
ParameterExpression param = Expressions.parameter(String.class);
// Creating an expression for the method call and specifying its
// parameter.
MethodCallExpression methodCall =
Expressions.call(
Integer.class,
"valueOf",
Collections.<Expression>singletonList(param));
// The following statement first creates an expression tree,
// then compiles it, and then runs it.
int x =
Expressions.<Function1<String, Integer>>lambda(
methodCall,
new ParameterExpression[] { param })
.getFunction()
.apply("1234");
assertEquals(1234, x);
}
示例3: testWriteTryCatch
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testWriteTryCatch() {
final ParameterExpression cce_ =
Expressions.parameter(Modifier.FINAL, ClassCastException.class, "cce");
final ParameterExpression re_ =
Expressions.parameter(0, RuntimeException.class, "re");
Node node =
Expressions.tryCatch(
Expressions.block(
Expressions.return_(null,
Expressions.call(Expressions.constant("foo"), "length"))),
Expressions.catch_(cce_,
Expressions.return_(null, Expressions.constant(null))),
Expressions.catch_(re_,
Expressions.return_(null,
Expressions.call(re_, "toString"))));
assertEquals(
"try {\n"
+ " return \"foo\".length();\n"
+ "} catch (final ClassCastException cce) {\n"
+ " return null;\n"
+ "} catch (RuntimeException re) {\n"
+ " return re.toString();\n"
+ "}\n",
Expressions.toString(node));
}
示例4: toRows
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
private Expression toRows(PhysType physType, Expression expression) {
if (physType.getFormat() == JavaRowFormat.SCALAR
&& Object[].class.isAssignableFrom(elementType)
&& getRowType().getFieldCount() == 1
&& (table.unwrap(ScannableTable.class) != null
|| table.unwrap(FilterableTable.class) != null
|| table.unwrap(ProjectableFilterableTable.class) != null)) {
return Expressions.call(BuiltInMethod.SLICE0.method, expression);
}
JavaRowFormat oldFormat = format();
if (physType.getFormat() == oldFormat && !hasCollectionField(rowType)) {
return expression;
}
final ParameterExpression row_ =
Expressions.parameter(elementType, "row");
final int fieldCount = table.getRowType().getFieldCount();
List<Expression> expressionList = new ArrayList<>(fieldCount);
for (int i = 0; i < fieldCount; i++) {
expressionList.add(fieldExpression(row_, i, physType, oldFormat));
}
return Expressions.call(expression,
BuiltInMethod.SELECT.method,
Expressions.lambda(Function1.class, physType.record(expressionList),
row_));
}
示例5: testConditionalIfBoolTrue
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testConditionalIfBoolTrue() {
// if (bool) {return 1} else if (true) {return 2}
Expression bool = Expressions.parameter(boolean.class, "bool");
assertEquals(
"{\n"
+ " if (bool) {\n"
+ " return 1;\n"
+ " } else {\n"
+ " return 2;\n"
+ " }\n"
+ "}\n",
optimize(
Expressions.ifThenElse(bool,
Expressions.return_(null, ONE),
TRUE,
Expressions.return_(null, TWO))));
}
示例6: testConditionalIfBoolTrueElse
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testConditionalIfBoolTrueElse() {
// if (bool) {return 1} else if (true) {return 2} else {return 3}
Expression bool = Expressions.parameter(boolean.class, "bool");
assertEquals(
"{\n"
+ " if (bool) {\n"
+ " return 1;\n"
+ " } else {\n"
+ " return 2;\n"
+ " }\n"
+ "}\n",
optimize(
Expressions.ifThenElse(bool,
Expressions.return_(null, ONE),
TRUE,
Expressions.return_(null, TWO),
Expressions.return_(null, THREE))));
}
示例7: compileToBlock
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
public BlockStatement compileToBlock(final RexProgram program) {
final ParameterExpression context_ =
Expressions.parameter(Context.class, "context");
final ParameterExpression outputValues_ =
Expressions.parameter(Object[].class, "outputValues");
return compileToBlock(program, context_, outputValues_).toBlock();
}
示例8: compile
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
public String compile(final RexProgram program, String className) {
final ParameterExpression context_ =
Expressions.parameter(Context.class, "context");
final ParameterExpression outputValues_ =
Expressions.parameter(Object[].class, "outputValues");
BlockBuilder builder = compileToBlock(program, context_, outputValues_);
return baz(context_, outputValues_, builder.toBlock(), className);
}
示例9: testOptimizeTernaryAeqBBA
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testOptimizeTernaryAeqBBA() {
// a == b ? b : a
ParameterExpression a = Expressions.parameter(boolean.class, "a");
ParameterExpression b = Expressions.parameter(boolean.class, "b");
assertEquals("{\n return a;\n}\n",
optimize(Expressions.condition(Expressions.equal(a, b), b, a)));
}
示例10: convertTo
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
public Expression convertTo(Expression exp, PhysType targetPhysType) {
final JavaRowFormat targetFormat = targetPhysType.getFormat();
if (format == targetFormat) {
return exp;
}
final ParameterExpression o_ =
Expressions.parameter(javaRowClass, "o");
final int fieldCount = rowType.getFieldCount();
return Expressions.call(exp, BuiltInMethod.SELECT.method,
generateSelector(o_, Util.range(fieldCount), targetFormat));
}
示例11: testOptimizeTernaryAneqBAB
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testOptimizeTernaryAneqBAB() {
// a != b ? a : b
ParameterExpression a = Expressions.parameter(boolean.class, "a");
ParameterExpression b = Expressions.parameter(boolean.class, "b");
assertEquals("{\n return a;\n}\n",
optimize(Expressions.condition(Expressions.notEqual(a, b), a, b)));
}
示例12: handleNull
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
/** Adapts an expression with "normal" result to one that adheres to
* this particular policy. Wraps the result expression into a new
* parameter if need be.
*
* @param input Expression
* @param nullAs If false, if expression is definitely not null at
* runtime. Therefore we can optimize. For example, we can cast to int
* using x.intValue().
* @return Translated expression
*/
public Expression handleNull(Expression input, RexImpTable.NullAs nullAs) {
final Expression nullHandled = nullAs.handle(input);
// If we get ConstantExpression, just return it (i.e. primitive false)
if (nullHandled instanceof ConstantExpression) {
return nullHandled;
}
// if nullHandled expression is the same as "input",
// then we can just reuse it
if (nullHandled == input) {
return input;
}
// If nullHandled is different, then it might be unsafe to compute
// early (i.e. unbox of null value should not happen _before_ ternary).
// Thus we wrap it into brand-new ParameterExpression,
// and we are guaranteed that ParameterExpression will not be shared
String unboxVarName = "v_unboxed";
if (input instanceof ParameterExpression) {
unboxVarName = ((ParameterExpression) input).name + "_unboxed";
}
ParameterExpression unboxed = Expressions.parameter(nullHandled.getType(),
list.newName(unboxVarName));
list.add(Expressions.declare(Modifier.FINAL, unboxed, nullHandled));
return unboxed;
}
示例13: testFor2
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testFor2() throws NoSuchFieldException {
final BlockBuilder builder = new BlockBuilder();
final ParameterExpression i_ = Expressions.parameter(int.class, "i");
final ParameterExpression j_ = Expressions.parameter(int.class, "j");
builder.add(
Expressions.for_(
Arrays.asList(
Expressions.declare(
0, i_, Expressions.constant(0)),
Expressions.declare(
0, j_, Expressions.constant(10))),
null,
null,
Expressions.block(
Expressions.ifThen(
Expressions.lessThan(
Expressions.preIncrementAssign(i_),
Expressions.preDecrementAssign(j_)),
Expressions.break_(null)))));
assertEquals(
"{\n"
+ " for (int i = 0, j = 10; ; ) {\n"
+ " if (++i < --j) {\n"
+ " break;\n"
+ " }\n"
+ " }\n"
+ "}\n",
Expressions.toString(builder.toBlock()));
}
示例14: testInlineParameter
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@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());
}
示例15: testWriteTryFinally
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testWriteTryFinally() {
final ParameterExpression cce_ =
Expressions.parameter(Modifier.FINAL, ClassCastException.class, "cce");
final ParameterExpression re_ =
Expressions.parameter(0, RuntimeException.class, "re");
Node node =
Expressions.ifThen(
Expressions.constant(true),
Expressions.tryFinally(
Expressions.block(
Expressions.return_(null,
Expressions.call(
Expressions.constant("foo"),
"length"))),
Expressions.statement(
Expressions.call(
Expressions.constant("foo"),
"toUpperCase"))));
assertEquals(
"if (true) {\n"
+ " try {\n"
+ " return \"foo\".length();\n"
+ " } finally {\n"
+ " \"foo\".toUpperCase();\n"
+ " }\n"
+ "}\n",
Expressions.toString(node));
}