本文整理汇总了Java中org.apache.calcite.linq4j.tree.BlockBuilder类的典型用法代码示例。如果您正苦于以下问题:Java BlockBuilder类的具体用法?Java BlockBuilder怎么用?Java BlockBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockBuilder类属于org.apache.calcite.linq4j.tree包,在下文中一共展示了BlockBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:SparkToEnumerableConverter.java
示例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());
}
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:EnumerableToSparkConverter.java
示例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()));
}
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:ExpressionTest.java
示例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());
}
开发者ID:apache,项目名称:calcite,代码行数:19,代码来源:BlockBuilderTest.java
示例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()));
}
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:InlinerTest.java
示例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));
}
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:InlinerTest.java
示例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()));
}
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:InlinerTest.java
示例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()));
}
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:InlinerTest.java
示例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());
}
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:EnumerableCollect.java
示例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());
}
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:EnumerableSemiJoin.java
示例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;
}
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:RexToLixTranslator.java
示例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);
}
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:RexToLixTranslator.java
示例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);
}
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:RexToLixTranslator.java
示例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());
}
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:EnumerableTableFunctionScan.java
示例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);
}
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:NestedBlockBuilderImpl.java
示例16: implement
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
final JavaTypeFactory typeFactory = implementor.getTypeFactory();
final BlockBuilder builder = new BlockBuilder();
final PhysType physType =
PhysTypeImpl.of(typeFactory, getRowType(), JavaRowFormat.ARRAY);
final Expression interpreter_ = builder.append("interpreter",
Expressions.new_(Interpreter.class,
implementor.getRootExpression(),
implementor.stash(getInput(), RelNode.class)));
final Expression sliced_ =
getRowType().getFieldCount() == 1
? Expressions.call(BuiltInMethod.SLICE0.method, interpreter_)
: interpreter_;
builder.add(sliced_);
return implementor.result(physType, builder.toBlock());
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:EnumerableInterpreter.java
示例17: getRowCollationKey
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
private Pair<Expression, Expression> getRowCollationKey(
BlockBuilder builder, PhysType inputPhysType,
Group group, int windowIdx) {
if (!(group.isRows || (group.upperBound.isUnbounded()
&& group.lowerBound.isUnbounded()))) {
Pair<Expression, Expression> pair =
inputPhysType.generateCollationKey(
group.collation().getFieldCollations());
// optimize=false to prevent inlining of object create into for-loops
return Pair.of(
builder.append("keySelector" + windowIdx, pair.left, false),
builder.append("keyComparator" + windowIdx, pair.right, false));
} else {
return Pair.of(null, null);
}
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:EnumerableWindow.java
示例18: implementAdd
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
private void implementAdd(List<AggImpState> aggs,
final BlockBuilder builder7,
final Function<BlockBuilder, WinAggFrameResultContext> frame,
final Function<AggImpState, List<RexNode>> rexArguments,
final DeclarationStatement jDecl) {
for (final AggImpState agg : aggs) {
final WinAggAddContext addContext =
new WinAggAddContextImpl(builder7, agg.state, frame) {
public Expression currentPosition() {
return jDecl.parameter;
}
public List<RexNode> rexArguments() {
return rexArguments.apply(agg);
}
public RexNode rexFilterArgument() {
return null; // REVIEW
}
};
agg.implementor.implementAdd(agg.context, addContext);
}
}
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:EnumerableWindow.java
示例19: field
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入依赖的package包/类
public Expression field(BlockBuilder list, int index, Type storageType) {
MethodCallExpression recFromCtx = Expressions.call(
DataContext.ROOT,
BuiltInMethod.DATA_CONTEXT_GET.method,
Expressions.constant("inputRecord"));
Expression recFromCtxCasted =
RexToLixTranslator.convert(recFromCtx, Object[].class);
IndexExpression recordAccess = Expressions.arrayIndex(recFromCtxCasted,
Expressions.constant(index));
if (storageType == null) {
final RelDataType fieldType =
rowType.getFieldList().get(index).getType();
storageType = ((JavaTypeFactory) typeFactory).getJavaClass(fieldType);
}
return RexToLixTranslator.convert(recordAccess, storageType);
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RexExecutorImpl.java
示例20: 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);
}
开发者ID:apache,项目名称:apex-malhar,代码行数:41,代码来源:ExpressionCompiler.java
注:本文中的org.apache.calcite.linq4j.tree.BlockBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论