当前位置: 首页>>代码示例>>Java>>正文


Java BlockBuilder.add方法代码示例

本文整理汇总了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());
}
 
开发者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: 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

示例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());
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:EnumerableCollect.java

示例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);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:41,代码来源:ExpressionCompiler.java

示例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;
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:38,代码来源:RexNodeToJavaCodeCompiler.java

示例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);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:38,代码来源:RexNodeToJavaCodeCompiler.java

示例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;
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:EnumerableWindow.java

示例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());
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:PigToEnumerableConverter.java

示例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());
}
 
开发者ID:apache,项目名称:calcite,代码行数:31,代码来源:ExpressionTest.java

示例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);
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:StrictAggImplementor.java

示例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_);
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:EnumerableThetaJoin.java

示例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()));
}
 
开发者ID:apache,项目名称:calcite,代码行数:30,代码来源:ExpressionTest.java

示例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());
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:BlockBuilderTest.java

示例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()))));
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:StrictAggImplementor.java


注:本文中的org.apache.calcite.linq4j.tree.BlockBuilder.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。