本文整理汇总了Java中org.apache.calcite.linq4j.tree.BlockBuilder.append方法的典型用法代码示例。如果您正苦于以下问题:Java BlockBuilder.append方法的具体用法?Java BlockBuilder.append怎么用?Java BlockBuilder.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.linq4j.tree.BlockBuilder
的用法示例。
在下文中一共展示了BlockBuilder.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: implement
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
// Generate:
// RDD rdd = ...;
// return SparkRuntime.asEnumerable(rdd);
final BlockBuilder list = new BlockBuilder();
final SparkRel child = (SparkRel) getInput();
final PhysType physType =
PhysTypeImpl.of(implementor.getTypeFactory(),
getRowType(),
JavaRowFormat.CUSTOM);
SparkRel.Implementor sparkImplementor =
new SparkImplementorImpl(implementor);
final SparkRel.Result result = child.implementSpark(sparkImplementor);
final Expression rdd = list.append("rdd", result.block);
final Expression enumerable =
list.append(
"enumerable",
Expressions.call(
SparkMethod.AS_ENUMERABLE.method,
rdd));
list.add(
Expressions.return_(null, enumerable));
return implementor.result(physType, list.toBlock());
}
示例2: implementSpark
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public Result implementSpark(Implementor implementor) {
// Generate:
// Enumerable source = ...;
// return SparkRuntime.createRdd(sparkContext, source);
final BlockBuilder list = new BlockBuilder();
final EnumerableRel child = (EnumerableRel) getInput();
final PhysType physType =
PhysTypeImpl.of(
implementor.getTypeFactory(), getRowType(),
JavaRowFormat.CUSTOM);
final Expression source = null; // TODO:
final Expression sparkContext =
Expressions.call(
SparkMethod.GET_SPARK_CONTEXT.method,
implementor.getRootExpression());
final Expression rdd =
list.append(
"rdd",
Expressions.call(
SparkMethod.CREATE_RDD.method,
sparkContext,
source));
list.add(
Expressions.return_(null, rdd));
return implementor.result(physType, list.toBlock());
}
示例3: testAssignInConditionMultipleUsage
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
@Test public void testAssignInConditionMultipleUsage() {
// int t;
// return (t = 1) != a ? t : c
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression t = Expressions.parameter(int.class, "t");
builder.add(Expressions.declare(0, t, null));
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;\n"
+ " return (t = 1) != a ? t : c;\n"
+ "}\n",
Expressions.toString(builder.toBlock()));
}
示例4: checkAssignInConditionOptimizedOut
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
void checkAssignInConditionOptimizedOut(int modifiers, String s) {
// int t;
// return (t = 1) != a ? b : c
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression t =
Expressions.parameter(int.class, "t");
builder.add(Expressions.declare(modifiers, t, null));
Expression v = builder.append("v",
Expressions.makeTernary(ExpressionType.Conditional,
Expressions.makeBinary(ExpressionType.NotEqual,
Expressions.assign(t, Expressions.constant(1)),
Expressions.parameter(int.class, "a")),
Expressions.parameter(int.class, "b"),
Expressions.parameter(int.class, "c")));
builder.add(Expressions.return_(null, v));
assertThat(Expressions.toString(builder.toBlock()),
CoreMatchers.equalTo(s));
}
示例5: testAssignInConditionMultipleUsageNonOptimized
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的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()));
}
示例6: testMultiPassOptimization
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
@Test public void testMultiPassOptimization() {
// int t = u + v;
// boolean b = t > 1 ? true : true; -- optimized out, thus t can be inlined
// return b ? t : 2
final BlockBuilder builder = new BlockBuilder(true);
final ParameterExpression u = Expressions.parameter(int.class, "u");
final ParameterExpression v = Expressions.parameter(int.class, "v");
Expression t = builder.append("t", Expressions.add(u, v));
Expression b = builder.append("b",
Expressions.condition(Expressions.greaterThan(t, ONE), TRUE, TRUE));
builder.add(Expressions.return_(null, Expressions.condition(b, t, TWO)));
assertEquals(
"{\n"
+ " return u + v;\n"
+ "}\n",
Expressions.toString(builder.toBlock()));
}
示例7: implement
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
final BlockBuilder builder = new BlockBuilder();
final EnumerableRel child = (EnumerableRel) getInput();
final Result result = implementor.visitChild(this, 0, child, Prefer.ARRAY);
final PhysType physType =
PhysTypeImpl.of(
implementor.getTypeFactory(),
getRowType(),
JavaRowFormat.LIST);
// final Enumerable<Employee> child = <<child adapter>>;
// final List<Employee> list = child.toList();
Expression child_ =
builder.append(
"child", result.block);
Expression list_ =
builder.append("list",
Expressions.call(child_,
BuiltInMethod.ENUMERABLE_TO_LIST.method));
builder.add(
Expressions.return_(null,
Expressions.call(
BuiltInMethod.SINGLETON_ENUMERABLE.method, list_)));
return implementor.result(physType, builder.toBlock());
}
示例8: implement
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
BlockBuilder builder = new BlockBuilder();
final Result leftResult =
implementor.visitChild(this, 0, (EnumerableRel) left, pref);
Expression leftExpression =
builder.append(
"left", leftResult.block);
final Result rightResult =
implementor.visitChild(this, 1, (EnumerableRel) right, pref);
Expression rightExpression =
builder.append(
"right", rightResult.block);
final PhysType physType = leftResult.physType;
return implementor.result(
physType,
builder.append(
Expressions.call(
BuiltInMethod.SEMI_JOIN.method,
Expressions.list(
leftExpression,
rightExpression,
leftResult.physType.generateAccessor(leftKeys),
rightResult.physType.generateAccessor(rightKeys))))
.toBlock());
}
示例9: baz
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的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);
}
示例10: checkBlockBuilder
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public void checkBlockBuilder(boolean optimizing, String expected) {
BlockBuilder statements = new BlockBuilder(optimizing);
Expression one =
statements.append(
"one", Expressions.constant(1));
Expression two =
statements.append(
"two", Expressions.constant(2));
Expression three =
statements.append(
"three", Expressions.add(one, two));
Expression six =
statements.append(
"six",
Expressions.multiply(three, two));
Expression nine =
statements.append(
"nine",
Expressions.multiply(three, three));
Expression eighteen =
statements.append(
"eighteen",
Expressions.add(
Expressions.add(three, six),
nine));
statements.add(Expressions.return_(null, eighteen));
BlockStatement expression = statements.toBlock();
assertEquals(expected, Expressions.toString(expression));
expression.accept(new Shuttle());
}
示例11: implement
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
final BlockBuilder builder = new BlockBuilder();
final EnumerableRel child = (EnumerableRel) getInput();
final Result result = implementor.visitChild(this, 0, child, pref);
final PhysType physType =
PhysTypeImpl.of(
implementor.getTypeFactory(),
getRowType(),
result.format);
Expression childExp =
builder.append("child", result.block);
PhysType inputPhysType = result.physType;
final Pair<Expression, Expression> pair =
inputPhysType.generateCollationKey(
collation.getFieldCollations());
builder.add(
Expressions.return_(null,
Expressions.call(childExp,
BuiltInMethod.ORDER_BY.method,
Expressions.list(
builder.append("keySelector", pair.left))
.appendIfNotNull(
builder.appendIfNotNull("comparator", pair.right)))));
return implementor.result(physType, builder.toBlock());
}
示例12: testReuseExpressionsFromUpperLevel
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
@Test public void testReuseExpressionsFromUpperLevel() {
Expression x = b.append("x", Expressions.add(ONE, TWO));
BlockBuilder nested = new BlockBuilder(true, b);
Expression y = nested.append("y", Expressions.add(ONE, TWO));
nested.add(Expressions.return_(null, Expressions.add(y, y)));
b.add(nested.toBlock());
assertEquals(
"{\n"
+ " final int x = 1 + 2;\n"
+ " {\n"
+ " return x + x;\n"
+ " }\n"
+ "}\n",
b.toBlock().toString());
}
示例13: implement
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
@Override public Result implement(EnumerableRelImplementor implementor, Prefer prefer) {
final BlockBuilder list = new BlockBuilder();
final ElasticsearchRel.Implementor elasticsearchImplementor =
new ElasticsearchRel.Implementor();
elasticsearchImplementor.visitChild(0, getInput());
final RelDataType rowType = getRowType();
final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), rowType,
prefer.prefer(JavaRowFormat.ARRAY));
final Expression fields = list.append("fields",
constantArrayList(
Pair.zip(ElasticsearchRules.elasticsearchFieldNames(rowType),
new AbstractList<Class>() {
@Override public Class get(int index) {
return physType.fieldClass(index);
}
@Override public int size() {
return rowType.getFieldCount();
}
}),
Pair.class));
final Expression table = list.append("table",
elasticsearchImplementor.table
.getExpression(AbstractElasticsearchTable.ElasticsearchQueryable.class));
List<String> opList = elasticsearchImplementor.list;
final Expression ops = list.append("ops", constantArrayList(opList, String.class));
Expression enumerable = list.append("enumerable",
Expressions.call(table, ElasticsearchMethod.ELASTICSEARCH_QUERYABLE_FIND.method, ops,
fields));
if (CalcitePrepareImpl.DEBUG) {
System.out.println("Elasticsearch: " + opList);
}
Hook.QUERY_PLAN.run(opList);
list.add(Expressions.return_(null, enumerable));
return implementor.result(physType, list.toBlock());
}
示例14: implement
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
final BlockBuilder builder = new BlockBuilder();
final EnumerableRel child = (EnumerableRel) getInput();
final Result result = implementor.visitChild(this, 0, child, pref);
final PhysType physType =
PhysTypeImpl.of(
implementor.getTypeFactory(),
getRowType(),
result.format);
Expression v = builder.append("child", result.block);
if (offset != null) {
v = builder.append(
"offset",
Expressions.call(
v,
BuiltInMethod.SKIP.method,
getExpression(offset)));
}
if (fetch != null) {
v = builder.append(
"fetch",
Expressions.call(
v,
BuiltInMethod.TAKE.method,
getExpression(fetch)));
}
builder.add(
Expressions.return_(
null,
v));
return implementor.result(physType, builder.toBlock());
}
示例15: field
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public Expression field(BlockBuilder list, int index, Type storageType) {
int offset = 0;
for (Pair<Expression, PhysType> input : inputs) {
final PhysType physType = input.right;
int fieldCount = physType.getRowType().getFieldCount();
if (index >= offset + fieldCount) {
offset += fieldCount;
continue;
}
final Expression left = list.append("current", input.left);
return physType.fieldReference(left, index - offset, storageType);
}
throw new IllegalArgumentException("Unable to find field #" + index);
}