本文整理汇总了Java中org.apache.calcite.linq4j.tree.BlockBuilder.add方法的典型用法代码示例。如果您正苦于以下问题:Java BlockBuilder.add方法的具体用法?Java BlockBuilder.add怎么用?Java BlockBuilder.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.linq4j.tree.BlockBuilder
的用法示例。
在下文中一共展示了BlockBuilder.add方法的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: 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));
}
示例4: 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());
}
示例5: getExpression
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
/**
* Create quasi-Java expression from given {@link RexNode}
*
* @param node Expression in the form of {@link RexNode}
* @param inputRowType Input Data type to expression in the form of {@link RelDataType}
* @param outputRowType Output data type of expression in the form of {@link RelDataType}
*
* @return Returns quasi-Java expression
*/
public String getExpression(RexNode node, RelDataType inputRowType, RelDataType outputRowType)
{
final RexProgramBuilder programBuilder = new RexProgramBuilder(inputRowType, rexBuilder);
programBuilder.addProject(node, null);
final RexProgram program = programBuilder.getProgram();
final BlockBuilder builder = new BlockBuilder();
final JavaTypeFactory javaTypeFactory = (JavaTypeFactory)rexBuilder.getTypeFactory();
final RexToLixTranslator.InputGetter inputGetter = new RexToLixTranslator.InputGetterImpl(ImmutableList
.of(Pair.<Expression, PhysType>of(Expressions.variable(Object[].class, "inputValues"),
PhysTypeImpl.of(javaTypeFactory, inputRowType, JavaRowFormat.ARRAY, false))));
final Function1<String, RexToLixTranslator.InputGetter> correlates =
new Function1<String, RexToLixTranslator.InputGetter>()
{
public RexToLixTranslator.InputGetter apply(String a0)
{
throw new UnsupportedOperationException();
}
};
final List<Expression> list = RexToLixTranslator.translateProjects(program, javaTypeFactory, builder,
PhysTypeImpl.of(javaTypeFactory, outputRowType, JavaRowFormat.ARRAY, false), null, inputGetter, correlates);
for (int i = 0; i < list.size(); i++) {
Statement statement = Expressions.statement(list.get(i));
builder.add(statement);
}
return finalizeExpression(builder.toBlock(), inputRowType);
}
示例6: compileToBlock
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
private BlockBuilder compileToBlock(final RexProgram program, ParameterExpression context_,
ParameterExpression outputValues_) {
RelDataType inputRowType = program.getInputRowType();
final BlockBuilder builder = new BlockBuilder();
final JavaTypeFactoryImpl javaTypeFactory =
new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem());
final RexToLixTranslator.InputGetter inputGetter =
new RexToLixTranslator.InputGetterImpl(
ImmutableList.of(
Pair.<Expression, PhysType>of(
Expressions.field(context_,
BuiltInMethod.CONTEXT_VALUES.field),
PhysTypeImpl.of(javaTypeFactory, inputRowType,
JavaRowFormat.ARRAY, false))));
final Function1<String, RexToLixTranslator.InputGetter> correlates =
new Function1<String, RexToLixTranslator.InputGetter>() {
public RexToLixTranslator.InputGetter apply(String a0) {
throw new UnsupportedOperationException();
}
};
final Expression root =
Expressions.field(context_, BuiltInMethod.CONTEXT_ROOT.field);
final List<Expression> list =
RexToLixTranslator.translateProjects(program, javaTypeFactory, builder,
null, root, inputGetter, correlates);
for (int i = 0; i < list.size(); i++) {
builder.add(
Expressions.statement(
Expressions.assign(
Expressions.arrayIndex(outputValues_,
Expressions.constant(i)),
list.get(i))));
}
return builder;
}
示例7: 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);
}
示例8: implementResult
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
private boolean implementResult(List<AggImpState> aggs,
final BlockBuilder builder,
final Function<BlockBuilder, WinAggFrameResultContext> frame,
final Function<AggImpState, List<RexNode>> rexArguments,
boolean cachedBlock) {
boolean nonEmpty = false;
for (final AggImpState agg : aggs) {
boolean needCache = true;
if (agg.implementor instanceof WinAggImplementor) {
WinAggImplementor imp = (WinAggImplementor) agg.implementor;
needCache = imp.needCacheWhenFrameIntact();
}
if (needCache ^ cachedBlock) {
// Regular aggregates do not change when the windowing frame keeps
// the same. Ths
continue;
}
nonEmpty = true;
Expression res = agg.implementor.implementResult(agg.context,
new WinAggResultContextImpl(builder, agg.state, frame) {
public List<RexNode> rexArguments() {
return rexArguments.apply(agg);
}
});
// Several count(a) and count(b) might share the result
Expression aggRes = builder.append("a" + agg.aggIdx + "res",
RexToLixTranslator.convert(res, agg.result.getType()));
builder.add(
Expressions.statement(Expressions.assign(agg.result, aggRes)));
}
return nonEmpty;
}
示例9: implement
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* <p>This implementation does not actually execute the associated Pig Latin
* script and return results. Instead it returns an empty
* {@link org.apache.calcite.adapter.enumerable.EnumerableRel.Result}
* in order to allow for testing and verification of every step of query
* processing up to actual physical execution and result verification.
*
* <p>Next step is to invoke Pig from here, likely in local mode, have it
* store results in a predefined file so they can be read here and returned as
* a {@code Result} object.
*/
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
final BlockBuilder list = new BlockBuilder();
final PhysType physType =
PhysTypeImpl.of(implementor.getTypeFactory(), rowType,
pref.prefer(JavaRowFormat.ARRAY));
PigRel.Implementor impl = new PigRel.Implementor();
impl.visitChild(0, getInput());
Hook.QUERY_PLAN.run(impl.getScript()); // for script validation in tests
list.add(
Expressions.return_(null,
Expressions.call(
BuiltInMethod.EMPTY_ENUMERABLE.method)));
return implementor.result(physType, list.toBlock());
}
示例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: implementReset
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public final void implementReset(AggContext info, AggResetContext reset) {
if (trackNullsPerRow) {
List<Expression> acc = reset.accumulator();
Expression flag = acc.get(acc.size() - 1);
BlockBuilder block = reset.currentBlock();
block.add(
Expressions.statement(
Expressions.assign(flag,
RexImpTable.getDefaultValue(flag.getType()))));
}
implementNotNullReset(info, reset);
}
示例12: predicate
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
Expression predicate(EnumerableRelImplementor implementor,
BlockBuilder builder, PhysType leftPhysType, PhysType rightPhysType,
RexNode condition) {
final ParameterExpression left_ =
Expressions.parameter(leftPhysType.getJavaRowType(), "left");
final ParameterExpression right_ =
Expressions.parameter(rightPhysType.getJavaRowType(), "right");
final RexProgramBuilder program =
new RexProgramBuilder(
implementor.getTypeFactory().builder()
.addAll(left.getRowType().getFieldList())
.addAll(right.getRowType().getFieldList())
.build(),
getCluster().getRexBuilder());
program.addCondition(condition);
builder.add(
Expressions.return_(null,
RexToLixTranslator.translateCondition(program.getProgram(),
implementor.getTypeFactory(),
builder,
new RexToLixTranslator.InputGetterImpl(
ImmutableList.of(Pair.of((Expression) left_, leftPhysType),
Pair.of((Expression) right_, rightPhysType))),
implementor.allCorrelateVariables)));
return Expressions.lambda(Predicate2.class, builder.toBlock(), left_,
right_);
}
示例13: testFor2
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的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: 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());
}
示例15: implementNotNullReset
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
protected void implementNotNullReset(AggContext info,
AggResetContext reset) {
BlockBuilder block = reset.currentBlock();
List<Expression> accumulator = reset.accumulator();
for (int i = 0; i < getStateSize(); i++) {
Expression exp = accumulator.get(i);
block.add(
Expressions.statement(
Expressions.assign(exp,
RexImpTable.getDefaultValue(exp.getType()))));
}
}