本文整理汇总了Java中org.apache.calcite.linq4j.tree.BlockBuilder类的典型用法代码示例。如果您正苦于以下问题:Java BlockBuilder类的具体用法?Java BlockBuilder怎么用?Java BlockBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockBuilder类属于org.apache.calcite.linq4j.tree包,在下文中一共展示了BlockBuilder类的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: testFor
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
@Test public void testFor() throws NoSuchFieldException {
final BlockBuilder builder = new BlockBuilder();
final ParameterExpression i_ = Expressions.parameter(int.class, "i");
builder.add(
Expressions.for_(
Expressions.declare(
0, i_, Expressions.constant(0)),
Expressions.lessThan(i_, Expressions.constant(10)),
Expressions.postIncrementAssign(i_),
Expressions.block(
Expressions.statement(
Expressions.call(
Expressions.field(
null, System.class.getField("out")),
"println",
i_)))));
assertEquals(
"{\n"
+ " for (int i = 0; i < 10; i++) {\n"
+ " System.out.println(i);\n"
+ " }\n"
+ "}\n",
Expressions.toString(builder.toBlock()));
}
示例4: testTestCustomOptimizer
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
@Test public void testTestCustomOptimizer() {
BlockBuilder b = new BlockBuilder() {
@Override protected Shuttle createOptimizeShuttle() {
return new OptimizeShuttle() {
@Override public Expression visit(BinaryExpression binary,
Expression expression0, Expression expression1) {
if (binary.getNodeType() == ExpressionType.Add
&& ONE.equals(expression0) && TWO.equals(expression1)) {
return FOUR;
}
return super.visit(binary, expression0, expression1);
}
};
}
};
b.add(Expressions.return_(null, Expressions.add(ONE, TWO)));
assertEquals("{\n return 4;\n}\n", b.toBlock().toString());
}
示例5: 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()));
}
示例6: 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));
}
示例7: 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()));
}
示例8: 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()));
}
示例9: 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());
}
示例10: 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());
}
示例11: RexToLixTranslator
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
private RexToLixTranslator(
RexProgram program,
JavaTypeFactory typeFactory,
Expression root,
InputGetter inputGetter,
BlockBuilder list,
Map<? extends RexNode, Boolean> exprNullableMap,
RexBuilder builder,
RexToLixTranslator parent,
Function1<String, InputGetter> correlates) {
this.program = program;
this.typeFactory = typeFactory;
this.root = root;
this.inputGetter = inputGetter;
this.list = list;
this.exprNullableMap = exprNullableMap;
this.builder = builder;
this.parent = parent;
this.correlates = correlates;
}
示例12: translateProjects
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
/**
* Translates a {@link RexProgram} to a sequence of expressions and
* declarations.
*
* @param program Program to be translated
* @param typeFactory Type factory
* @param list List of statements, populated with declarations
* @param outputPhysType Output type, or null
* @param root Root expression
* @param inputGetter Generates expressions for inputs
* @param correlates Provider of references to the values of correlated
* variables
* @return Sequence of expressions, optional condition
*/
public static List<Expression> translateProjects(RexProgram program,
JavaTypeFactory typeFactory,
BlockBuilder list,
PhysType outputPhysType,
Expression root,
InputGetter inputGetter,
Function1<String, InputGetter> correlates) {
List<Type> storageTypes = null;
if (outputPhysType != null) {
final RelDataType rowType = outputPhysType.getRowType();
storageTypes = new ArrayList<>(rowType.getFieldCount());
for (int i = 0; i < rowType.getFieldCount(); i++) {
storageTypes.add(outputPhysType.getJavaFieldType(i));
}
}
return new RexToLixTranslator(program, typeFactory, root, inputGetter, list)
.setCorrelates(correlates)
.translateList(program.getProjectList(), storageTypes);
}
示例13: translateCondition
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
public static Expression translateCondition(
RexProgram program,
JavaTypeFactory typeFactory,
BlockBuilder list,
InputGetter inputGetter,
Function1<String, InputGetter> correlates) {
if (program.getCondition() == null) {
return RexImpTable.TRUE_EXPR;
}
final ParameterExpression root = DataContext.ROOT;
RexToLixTranslator translator =
new RexToLixTranslator(program, typeFactory, root, inputGetter, list);
translator = translator.setCorrelates(correlates);
return translator.translate(
program.getCondition(),
RexImpTable.NullAs.FALSE);
}
示例14: implement
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
BlockBuilder bb = new BlockBuilder();
// Non-array user-specified types are not supported yet
final JavaRowFormat format;
if (getElementType() == null) {
format = JavaRowFormat.ARRAY;
} else if (rowType.getFieldCount() == 1 && isQueryable()) {
format = JavaRowFormat.SCALAR;
} else if (getElementType() instanceof Class
&& Object[].class.isAssignableFrom((Class) getElementType())) {
format = JavaRowFormat.ARRAY;
} else {
format = JavaRowFormat.CUSTOM;
}
final PhysType physType =
PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), format,
false);
RexToLixTranslator t = RexToLixTranslator.forAggregation(
(JavaTypeFactory) getCluster().getTypeFactory(), bb, null);
t = t.setCorrelates(implementor.allCorrelateVariables);
bb.add(Expressions.return_(null, t.translate(getCall())));
return implementor.result(physType, bb.toBlock());
}
示例15: nestBlock
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
/**
* Uses given block as the new code context and the map of nullability.
* The current block will be restored after {@link #exitBlock()} call.
* @param block new code block
* @param nullables map of expression to its nullability state
* @see #exitBlock()
*/
public final void nestBlock(BlockBuilder block,
Map<RexNode, Boolean> nullables) {
blocks.add(block);
Map<RexNode, Boolean> prev = this.nullables.isEmpty()
? Collections.<RexNode, Boolean>emptyMap()
: this.nullables.get(this.nullables.size() - 1);
Map<RexNode, Boolean> next;
if (nullables == null || nullables.isEmpty()) {
next = prev;
} else {
next = new HashMap<RexNode, Boolean>(nullables);
next.putAll(prev);
next = Collections.unmodifiableMap(next);
}
this.nullables.add(next);
}