本文整理汇总了Java中org.apache.calcite.linq4j.tree.Expressions.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Expressions.toString方法的具体用法?Java Expressions.toString怎么用?Java Expressions.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.linq4j.tree.Expressions
的用法示例。
在下文中一共展示了Expressions.toString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finalizeExpression
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
private String finalizeExpression(BlockStatement blockStatement, RelDataType inputRowType)
{
String s = Expressions.toString(blockStatement.statements.get(0));
int idx = 0;
for (RelDataTypeField field : inputRowType.getFieldList()) {
String fieldName = OperatorUtils.getFieldName(field);
s = s.replaceAll(String.format("inputValues\\[%d\\]", idx++), "\\{\\$." + Matcher.quoteReplacement(fieldName) + "\\}");
}
return s.substring(0, s.length() - 2);
}
示例2: baz
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
/** Given a method that implements {@link ExecutableExpression#execute(Context, Object[])},
* adds a bridge method that implements {@link ExecutableExpression#execute(Context)}, and
* compiles. */
static String baz(ParameterExpression context_,
ParameterExpression outputValues_, BlockStatement block, String className) {
final List<MemberDeclaration> declarations = Lists.newArrayList();
// public void execute(Context, Object[] outputValues)
declarations.add(
Expressions.methodDecl(Modifier.PUBLIC, void.class,
StreamlineBuiltInMethod.EXPR_EXECUTE2.method.getName(),
ImmutableList.of(context_, outputValues_), block));
// public Object execute(Context)
final BlockBuilder builder = new BlockBuilder();
final Expression values_ = builder.append("values",
Expressions.newArrayBounds(Object.class, 1,
Expressions.constant(1)));
builder.add(
Expressions.statement(
Expressions.call(
Expressions.parameter(ExecutableExpression.class, "this"),
StreamlineBuiltInMethod.EXPR_EXECUTE2.method, context_, values_)));
builder.add(
Expressions.return_(null,
Expressions.arrayIndex(values_, Expressions.constant(0))));
declarations.add(
Expressions.methodDecl(Modifier.PUBLIC, Object.class,
StreamlineBuiltInMethod.EXPR_EXECUTE1.method.getName(),
ImmutableList.of(context_), builder.toBlock()));
final ClassDeclaration classDeclaration =
Expressions.classDecl(Modifier.PUBLIC, className, null,
ImmutableList.<Type>of(ExecutableExpression.class), declarations);
return Expressions.toString(Lists.newArrayList(classDeclaration), "\n", false);
}
示例3: testLambdaPrimitiveTwoArgs
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testLambdaPrimitiveTwoArgs() {
// Parameters for the lambda expression.
ParameterExpression paramExpr =
Expressions.parameter(int.class, "key");
ParameterExpression param2Expr =
Expressions.parameter(int.class, "key2");
FunctionExpression lambdaExpr = Expressions.lambda(
Expressions.block(
(Type) null,
Expressions.return_(
null, paramExpr)),
Arrays.asList(paramExpr, param2Expr));
// Print out the expression.
String s = Expressions.toString(lambdaExpr);
assertEquals("new org.apache.calcite.linq4j.function.Function2() {\n"
+ " public int apply(int key, int key2) {\n"
+ " return key;\n"
+ " }\n"
+ " public Integer apply(Integer key, Integer key2) {\n"
+ " return apply(\n"
+ " key.intValue(),\n"
+ " key2.intValue());\n"
+ " }\n"
+ " public Integer apply(Object key, Object key2) {\n"
+ " return apply(\n"
+ " (Integer) key,\n"
+ " (Integer) key2);\n"
+ " }\n"
+ "}\n",
s);
}
示例4: toBindable
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
public static Bindable toBindable(Map<String, Object> parameters,
CalcitePrepare.SparkHandler spark, EnumerableRel rel,
EnumerableRel.Prefer prefer) {
EnumerableRelImplementor relImplementor =
new EnumerableRelImplementor(rel.getCluster().getRexBuilder(),
parameters);
final ClassDeclaration expr = relImplementor.implementRoot(rel, prefer);
String s = Expressions.toString(expr.memberDeclarations, "\n", false);
if (CalcitePrepareImpl.DEBUG) {
Util.debugCode(System.out, s);
}
Hook.JAVA_PLAN.run(s);
try {
if (spark != null && spark.enabled()) {
return spark.compile(expr, s);
} else {
return getBindable(expr, s, rel.getRowType().getFieldCount());
}
} catch (Exception e) {
throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n"
+ s, e);
}
}
示例5: compile
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
private String compile(RexBuilder rexBuilder, List<RexNode> constExps,
RexToLixTranslator.InputGetter getter, RelDataType rowType) {
final RexProgramBuilder programBuilder =
new RexProgramBuilder(rowType, rexBuilder);
for (RexNode node : constExps) {
programBuilder.addProject(
node, "c" + programBuilder.getProjectList().size());
}
final JavaTypeFactoryImpl javaTypeFactory =
new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem());
final BlockBuilder blockBuilder = new BlockBuilder();
final ParameterExpression root0_ =
Expressions.parameter(Object.class, "root0");
final ParameterExpression root_ = DataContext.ROOT;
blockBuilder.add(
Expressions.declare(
Modifier.FINAL, root_,
Expressions.convert_(root0_, DataContext.class)));
final List<Expression> expressions =
RexToLixTranslator.translateProjects(programBuilder.getProgram(),
javaTypeFactory, blockBuilder, null, root_, getter, null);
blockBuilder.add(
Expressions.return_(null,
Expressions.newArrayInit(Object[].class, expressions)));
final MethodDeclaration methodDecl =
Expressions.methodDecl(Modifier.PUBLIC, Object[].class,
BuiltInMethod.FUNCTION1_APPLY.method.getName(),
ImmutableList.of(root0_), blockBuilder.toBlock());
String code = Expressions.toString(methodDecl);
if (CalcitePrepareImpl.DEBUG) {
Util.debugCode(System.out, code);
}
return code;
}
示例6: createSamzaExpressionFromCalcite
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
/**
* This method takes the java statement block, inputs, outputs needed by the statement block to create an object
* of class that implements the interface {@link Expression}
*
* for e.g.
* Query : select id from profile
* where profile table has relational schema with id(NUMBER) and name(VARCHAR) columns.
* This query will result in the following relational plan
* LogicalProject(id=[$1])
* LogicalTableScan(table=[[profile]])
*
*
* And the corresponding expressions are
* inputs : EnumerableTableScan (Which is the output of LogicalTableScan)
* nodes : [$1] Which essentially means take pick the first column from the input
*
* This expression corresponding to the logicalProject "[$1]" gets converted into a java statement block
* {
* outputValues[0] = (Integer) inputValues[1];
* }
*
* This method converts this statement block into an equivalent {@link Expression} object whose execute methods
* execute the above java statement block
*
*/
static org.apache.samza.sql.data.Expression createSamzaExpressionFromCalcite(ParameterExpression executionContext,
ParameterExpression dataContext, ParameterExpression inputValues, ParameterExpression outputValues,
BlockStatement block) {
final List<MemberDeclaration> declarations = Lists.newArrayList();
// public void execute(Object[] inputValues, Object[] outputValues)
declarations.add(
Expressions.methodDecl(Modifier.PUBLIC, void.class, SamzaBuiltInMethod.EXPR_EXECUTE2.method.getName(),
ImmutableList.of(executionContext, dataContext, inputValues, outputValues), block));
final ClassDeclaration classDeclaration = Expressions.classDecl(Modifier.PUBLIC, "SqlExpression", null,
ImmutableList.<Type>of(org.apache.samza.sql.data.Expression.class), declarations);
String s = Expressions.toString(declarations, "\n", false);
log.info("Generated code for expression: {}", s);
try {
return getExpression(classDeclaration, s);
} catch (Exception e) {
throw new SamzaException("Expression compilation failure.", e);
}
}
示例7: testLambdaCallsBinaryOp
import org.apache.calcite.linq4j.tree.Expressions; //导入方法依赖的package包/类
@Test public void testLambdaCallsBinaryOp() {
// A parameter for the lambda expression.
ParameterExpression paramExpr =
Expressions.parameter(Double.TYPE, "arg");
// This expression represents a lambda expression
// that adds 1 to the parameter value.
FunctionExpression lambdaExpr = Expressions.lambda(
Expressions.add(
paramExpr,
Expressions.constant(2d)),
Arrays.asList(paramExpr));
// Print out the expression.
String s = Expressions.toString(lambdaExpr);
assertEquals(
"new org.apache.calcite.linq4j.function.Function1() {\n"
+ " public double apply(double arg) {\n"
+ " return arg + 2.0D;\n"
+ " }\n"
+ " public Object apply(Double arg) {\n"
+ " return apply(\n"
+ " arg.doubleValue());\n"
+ " }\n"
+ " public Object apply(Object arg) {\n"
+ " return apply(\n"
+ " (Double) arg);\n"
+ " }\n"
+ "}\n",
s);
// Compile and run the lambda expression.
// The value of the parameter is 1.5.
double n = (Double) lambdaExpr.compile().dynamicInvoke(1.5d);
// This code example produces the following output:
//
// arg => (arg +2)
// 3
assertEquals(3.5D, n, 0d);
}