本文整理汇总了Java中org.apache.calcite.linq4j.tree.Expressions.constant方法的典型用法代码示例。如果您正苦于以下问题:Java Expressions.constant方法的具体用法?Java Expressions.constant怎么用?Java Expressions.constant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.linq4j.tree.Expressions
的用法示例。
在下文中一共展示了Expressions.constant方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAssign2
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@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"));
}
示例2: testApproxConstant
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
/** We use BigDecimal to represent literals of float and double using
* BigDecimal, because we want an exact representation. */
@Test public void testApproxConstant() {
ConstantExpression c;
c = Expressions.constant(new BigDecimal("3.1"), float.class);
assertThat(Expressions.toString(c), equalTo("3.1F"));
c = Expressions.constant(new BigDecimal("-5.156"), float.class);
assertThat(Expressions.toString(c), equalTo("-5.156F"));
c = Expressions.constant(new BigDecimal("-51.6"), Float.class);
assertThat(Expressions.toString(c), equalTo("Float.valueOf(-51.6F)"));
c = Expressions.constant(new BigDecimal(Float.MAX_VALUE), Float.class);
assertThat(Expressions.toString(c),
equalTo("Float.valueOf(Float.intBitsToFloat(2139095039))"));
c = Expressions.constant(new BigDecimal(Float.MIN_VALUE), Float.class);
assertThat(Expressions.toString(c),
equalTo("Float.valueOf(Float.intBitsToFloat(1))"));
c = Expressions.constant(new BigDecimal("3.1"), double.class);
assertThat(Expressions.toString(c), equalTo("3.1D"));
c = Expressions.constant(new BigDecimal("-5.156"), double.class);
assertThat(Expressions.toString(c), equalTo("-5.156D"));
c = Expressions.constant(new BigDecimal("-51.6"), Double.class);
assertThat(Expressions.toString(c), equalTo("Double.valueOf(-51.6D)"));
c = Expressions.constant(new BigDecimal(Double.MAX_VALUE), Double.class);
assertThat(Expressions.toString(c),
equalTo("Double.valueOf(Double.longBitsToDouble(9218868437227405311L))"));
c = Expressions.constant(new BigDecimal(Double.MIN_VALUE), Double.class);
assertThat(Expressions.toString(c),
equalTo("Double.valueOf(Double.longBitsToDouble(1L))"));
}
示例3: stash
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
/**
* Stashes a value for the executor. Given values are de-duplicated if
* identical (see {@link java.util.IdentityHashMap}).
*
* <p>For instance, to pass {@code ArrayList} to your method, you can use
* {@code Expressions.call(method, implementor.stash(arrayList))}.
*
* <p>For simple literals (strings, numbers) the result is equivalent to
* {@link org.apache.calcite.linq4j.tree.Expressions#constant(Object, java.lang.reflect.Type)}.
*
* <p>Note: the input value is held in memory as long as the statement
* is alive. If you are using just a subset of its content, consider creating
* a slimmer holder.
*
* @param input Value to be stashed
* @param clazz Java class type of the value when it is used
* @param <T> Java class type of the value when it is used
* @return Expression that will represent {@code input} in runtime
*/
public <T> Expression stash(T input, Class<? super T> clazz) {
// Well-known final classes that can be used as literals
if (input == null
|| input instanceof String
|| input instanceof Boolean
|| input instanceof Byte
|| input instanceof Short
|| input instanceof Integer
|| input instanceof Long
|| input instanceof Float
|| input instanceof Double
) {
return Expressions.constant(input, clazz);
}
ParameterExpression cached = stashedParameters.get(input);
if (cached != null) {
return cached;
}
// "stashed" avoids name clash since this name will be used as the variable
// name at the very start of the method.
final String name = "v" + map.size() + "stashed";
final ParameterExpression x = Expressions.variable(clazz, name);
map.put(name, input);
stashedParameters.put(input, x);
return x;
}
示例4: getExpression
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
private static Expression getExpression(RexNode offset) {
if (offset instanceof RexDynamicParam) {
final RexDynamicParam param = (RexDynamicParam) offset;
return Expressions.convert_(
Expressions.call(DataContext.ROOT,
BuiltInMethod.DATA_CONTEXT_GET.method,
Expressions.constant("?" + param.getIndex())),
Integer.class);
} else {
return Expressions.constant(RexLiteral.intValue(offset));
}
}
示例5: getDefaultValue
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
static Expression getDefaultValue(Type type) {
if (Primitive.is(type)) {
Primitive p = Primitive.of(type);
return Expressions.constant(p.defaultValue, type);
}
return Expressions.constant(null, type);
}
示例6: implementNotNullReset
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Override protected void implementNotNullReset(AggContext info,
AggResetContext reset) {
Expression start = info.returnType() == BigDecimal.class
? Expressions.constant(BigDecimal.ZERO)
: Expressions.constant(0);
reset.currentBlock().add(
Expressions.statement(
Expressions.assign(reset.accumulator().get(0), start)));
}
示例7: implement
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
public Expression implement(
RexToLixTranslator translator,
RexCall call,
NullAs nullAs) {
switch (nullAs) {
case IS_NULL:
return Expressions.constant(false);
case IS_NOT_NULL:
return Expressions.constant(true);
}
final SqlOperator op = call.getOperator();
final Expression root = translator.getRoot();
if (op == CURRENT_USER
|| op == SESSION_USER
|| op == USER) {
return Expressions.constant("sa");
} else if (op == SYSTEM_USER) {
return Expressions.constant(System.getProperty("user.name"));
} else if (op == CURRENT_PATH
|| op == CURRENT_ROLE
|| op == CURRENT_CATALOG) {
// By default, the CURRENT_ROLE and CURRENT_CATALOG functions return the
// empty string because a role or a catalog has to be set explicitly.
return Expressions.constant("");
} else if (op == CURRENT_TIMESTAMP) {
return Expressions.call(BuiltInMethod.CURRENT_TIMESTAMP.method, root);
} else if (op == CURRENT_TIME) {
return Expressions.call(BuiltInMethod.CURRENT_TIME.method, root);
} else if (op == CURRENT_DATE) {
return Expressions.call(BuiltInMethod.CURRENT_DATE.method, root);
} else if (op == LOCALTIMESTAMP) {
return Expressions.call(BuiltInMethod.LOCAL_TIMESTAMP.method, root);
} else if (op == LOCALTIME) {
return Expressions.call(BuiltInMethod.LOCAL_TIME.method, root);
} else {
throw new AssertionError("unknown function " + op);
}
}
示例8: testAssign
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@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"));
}
示例9: testConstantExpression
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testConstantExpression() {
final Expression constant = Expressions.constant(
new Object[] {
1,
new Object[] {
(byte) 1, (short) 2, (int) 3, (long) 4,
(float) 5, (double) 6, (char) 7, true, "string", null
},
new AllType(true, (byte) 100, (char) 101, (short) 102, 103,
(long) 104, (float) 105, (double) 106, new BigDecimal(107),
new BigInteger("108"), "109", null)
});
assertEquals(
"new Object[] {\n"
+ " 1,\n"
+ " new Object[] {\n"
+ " (byte)1,\n"
+ " (short)2,\n"
+ " 3,\n"
+ " 4L,\n"
+ " 5.0F,\n"
+ " 6.0D,\n"
+ " (char)7,\n"
+ " true,\n"
+ " \"string\",\n"
+ " null},\n"
+ " new org.apache.calcite.linq4j.test.ExpressionTest.AllType(\n"
+ " true,\n"
+ " (byte)100,\n"
+ " (char)101,\n"
+ " (short)102,\n"
+ " 103,\n"
+ " 104L,\n"
+ " 105.0F,\n"
+ " 106.0D,\n"
+ " new java.math.BigDecimal(107L),\n"
+ " new java.math.BigInteger(\"108\"),\n"
+ " \"109\",\n"
+ " null)}",
constant.toString());
constant.accept(new Shuttle());
}
示例10: implementResult
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
public Expression implementResult(AggContext info,
AggResultContext result) {
WinAggResultContext winResult = (WinAggResultContext) result;
List<RexNode> rexArgs = winResult.rexArguments();
ParameterExpression res = Expressions.parameter(0, info.returnType(),
result.currentBlock().newName(isLead ? "lead" : "lag"));
Expression offset;
RexToLixTranslator currentRowTranslator =
winResult.rowTranslator(
winResult.computeIndex(Expressions.constant(0), SeekType.SET));
if (rexArgs.size() >= 2) {
// lead(x, offset) or lead(x, offset, default)
offset = currentRowTranslator.translate(
rexArgs.get(1), int.class);
} else {
offset = Expressions.constant(1);
}
if (!isLead) {
offset = Expressions.negate(offset);
}
Expression dstIndex = winResult.computeIndex(offset, SeekType.SET);
Expression rowInRange = winResult.rowInPartition(dstIndex);
BlockBuilder thenBlock = result.nestBlock();
Expression lagResult = winResult.rowTranslator(dstIndex).translate(
rexArgs.get(0), res.type);
thenBlock.add(Expressions.statement(Expressions.assign(res, lagResult)));
result.exitBlock();
BlockStatement thenBranch = thenBlock.toBlock();
Expression defaultValue = rexArgs.size() == 3
? currentRowTranslator.translate(rexArgs.get(2), res.type)
: getDefaultValue(res.type);
result.currentBlock().add(Expressions.declare(0, res, null));
result.currentBlock().add(
Expressions.ifThenElse(rowInRange, thenBranch,
Expressions.statement(Expressions.assign(res, defaultValue))));
return res;
}