• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RexProgramBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.calcite.rex.RexProgramBuilder的典型用法代码示例。如果您正苦于以下问题:Java RexProgramBuilder类的具体用法?Java RexProgramBuilder怎么用?Java RexProgramBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RexProgramBuilder类属于org.apache.calcite.rex包,在下文中一共展示了RexProgramBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onMatch

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final EnumerableFilter filter = call.rel(0);
  final RelNode input = filter.getInput();

  // Create a program containing a filter.
  final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
  final RelDataType inputRowType = input.getRowType();
  final RexProgramBuilder programBuilder =
      new RexProgramBuilder(inputRowType, rexBuilder);
  programBuilder.addIdentity();
  programBuilder.addCondition(filter.getCondition());
  final RexProgram program = programBuilder.getProgram();

  final EnumerableCalc calc = EnumerableCalc.create(input, program);
  call.transformTo(calc);
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:EnumerableFilterToCalcRule.java


示例2: testBuildProgram

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
 * Tests construction of a RexProgram.
 */
@Test public void testBuildProgram() {
  final RexProgramBuilder builder = createProg(0);
  final RexProgram program = builder.getProgram(false);
  final String programString = program.toString();
  TestUtil.assertEqualsVerbose(
      "(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], "
          + "expr#4=[+($0, $1)], expr#5=[+($0, $0)], expr#6=[+($t4, $t2)], "
          + "a=[$t6], b=[$t5])",
      programString);

  // Normalize the program using the RexProgramBuilder.normalize API.
  // Note that unused expression '77' is eliminated, input refs (e.g. $0)
  // become local refs (e.g. $t0), and constants are assigned to locals.
  final RexProgram normalizedProgram = program.normalize(rexBuilder, null);
  final String normalizedProgramString = normalizedProgram.toString();
  TestUtil.assertEqualsVerbose(
      "(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
          + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
          + "expr#6=[+($t0, $t0)], a=[$t5], b=[$t6])",
      normalizedProgramString);
}
 
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:RexProgramTest.java


示例3: testElimDups

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
 * Tests construction and normalization of a RexProgram.
 */
@Test public void testElimDups() {
  final RexProgramBuilder builder = createProg(1);
  final String unnormalizedProgram = builder.getProgram(false).toString();
  TestUtil.assertEqualsVerbose(
      "(expr#0..1=[{inputs}], expr#2=[+($0, 1)], expr#3=[77], "
          + "expr#4=[+($0, $1)], expr#5=[+($0, 1)], expr#6=[+($0, $t5)], "
          + "expr#7=[+($t4, $t2)], a=[$t7], b=[$t6])",
      unnormalizedProgram);

  // normalize eliminates duplicates (specifically "+($0, $1)")
  final RexProgramBuilder builder2 = createProg(1);
  final String program2 = builder2.getProgram(true).toString();
  TestUtil.assertEqualsVerbose(
      "(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
          + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
          + "expr#6=[+($t0, $t4)], a=[$t5], b=[$t6])",
      program2);
}
 
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:RexProgramTest.java


示例4: onMatch

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
    Filter topFilter = call.rel(0);
    Filter bottomFilter = call.rel(1);

    // use RexPrograms to merge the two FilterRels into a single program
    // so we can convert the two FilterRel conditions to directly
    // reference the bottom FilterRel's child
    RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder();
    RexProgram bottomProgram = createProgram(bottomFilter);
    RexProgram topProgram = createProgram(topFilter);

    RexProgram mergedProgram =
        RexProgramBuilder.mergePrograms(
            topProgram,
            bottomProgram,
            rexBuilder);

    RexNode newCondition =
        mergedProgram.expandLocalRef(
            mergedProgram.getCondition());

//    if(!RexUtil.isFlat(newCondition)){
//      RexCall newCall = (RexCall) newCondition;
//      newCondition = rexBuilder.makeFlatCall( newCall.getOperator(), newCall.getOperands());
//    }

    Filter newFilterRel =
        (Filter) filterFactory.createFilter(
            bottomFilter.getInput(),
            RexUtil.flatten(rexBuilder, newCondition));

    call.transformTo(newFilterRel);
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:34,代码来源:DrillMergeFilterRule.java


示例5: createProgram

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
 * Creates a RexProgram corresponding to a LogicalFilter
 *
 * @param filterRel the LogicalFilter
 * @return created RexProgram
 */
private RexProgram createProgram(Filter filterRel) {
  RexProgramBuilder programBuilder =
      new RexProgramBuilder(
          filterRel.getRowType(),
          filterRel.getCluster().getRexBuilder());
  programBuilder.addIdentity();
  programBuilder.addCondition(filterRel.getCondition());
  return programBuilder.getProgram();
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:16,代码来源:DrillMergeFilterRule.java


示例6: getExpression

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的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


示例7: compileToBlock

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public BlockStatement compileToBlock(List<RexNode> nodes, RelDataType inputRowType) {
  final RexProgramBuilder programBuilder =
      new RexProgramBuilder(inputRowType, rexBuilder);
  for (RexNode node : nodes) {
    programBuilder.addProject(node, null);
  }

  return compileToBlock(programBuilder.getProgram());
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:10,代码来源:RexNodeToJavaCodeCompiler.java


示例8: compile

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public String compile(List<RexNode> nodes, RelDataType inputRowType, String className) {
  final RexProgramBuilder programBuilder =
          new RexProgramBuilder(inputRowType, rexBuilder);
  for (RexNode node : nodes) {
    programBuilder.addProject(node, null);
  }

  return compile(programBuilder.getProgram(), className);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:10,代码来源:RexNodeToJavaCodeCompiler.java


示例9: implementEnumerable

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
@Override
public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) {
    // keep it for having clause
    RexBuilder rexBuilder = getCluster().getRexBuilder();
    RelDataType inputRowType = getInput().getRowType();
    RexProgramBuilder programBuilder = new RexProgramBuilder(inputRowType, rexBuilder);
    programBuilder.addIdentity();
    programBuilder.addCondition(this.condition);
    RexProgram program = programBuilder.getProgram();

    return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), //
            sole(inputs), program);
}
 
开发者ID:apache,项目名称:kylin,代码行数:14,代码来源:OLAPFilterRel.java


示例10: onMatch

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final Filter topFilter = call.rel(0);
  final Filter bottomFilter = call.rel(1);

  // use RexPrograms to merge the two FilterRels into a single program
  // so we can convert the two LogicalFilter conditions to directly
  // reference the bottom LogicalFilter's child
  RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder();
  RexProgram bottomProgram = createProgram(bottomFilter);
  RexProgram topProgram = createProgram(topFilter);

  RexProgram mergedProgram =
      RexProgramBuilder.mergePrograms(
          topProgram,
          bottomProgram,
          rexBuilder);

  RexNode newCondition =
      mergedProgram.expandLocalRef(
          mergedProgram.getCondition());

  final RelBuilder relBuilder = call.builder();
  relBuilder.push(bottomFilter.getInput())
      .filter(newCondition);

  call.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:FilterMergeRule.java


示例11: onMatch

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final LogicalFilter filter = call.rel(0);
  final LogicalCalc calc = call.rel(1);

  // Don't merge a filter onto a calc which contains windowed aggregates.
  // That would effectively be pushing a multiset down through a filter.
  // We'll have chance to merge later, when the over is expanded.
  if (calc.getProgram().containsAggs()) {
    return;
  }

  // Create a program containing the filter.
  final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
  final RexProgramBuilder progBuilder =
      new RexProgramBuilder(
          calc.getRowType(),
          rexBuilder);
  progBuilder.addIdentity();
  progBuilder.addCondition(filter.getCondition());
  RexProgram topProgram = progBuilder.getProgram();
  RexProgram bottomProgram = calc.getProgram();

  // Merge the programs together.
  RexProgram mergedProgram =
      RexProgramBuilder.mergePrograms(
          topProgram,
          bottomProgram,
          rexBuilder);
  final LogicalCalc newCalc =
      LogicalCalc.create(calc.getInput(), mergedProgram);
  call.transformTo(newCalc);
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:FilterCalcMergeRule.java


示例12: onMatch

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  LogicalCalc calc = call.rel(0);

  // Expand decimals in every expression in this program. If no
  // expression changes, don't apply the rule.
  final RexProgram program = calc.getProgram();
  if (!RexUtil.requiresDecimalExpansion(program, true)) {
    return;
  }

  final RexBuilder rexBuilder = calc.getCluster().getRexBuilder();
  final RexShuttle shuttle = new DecimalShuttle(rexBuilder);
  RexProgramBuilder programBuilder =
      RexProgramBuilder.create(
          rexBuilder,
          calc.getInput().getRowType(),
          program.getExprList(),
          program.getProjectList(),
          program.getCondition(),
          program.getOutputRowType(),
          shuttle,
          true);

  final RexProgram newProgram = programBuilder.getProgram();
  LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), newProgram);
  call.transformTo(newCalc);
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:ReduceDecimalsRule.java


示例13: predicate

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的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


示例14: testNormalize

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
 * Tests construction and normalization of a RexProgram.
 */
@Test public void testNormalize() {
  final RexProgramBuilder builder = createProg(0);
  final String program = builder.getProgram(true).toString();
  TestUtil.assertEqualsVerbose(
      "(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
          + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
          + "expr#6=[+($t0, $t0)], a=[$t5], b=[$t6])",
      program);
}
 
开发者ID:apache,项目名称:calcite,代码行数:13,代码来源:RexProgramTest.java


示例15: testDuplicateAnd

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
 * Checks translation of AND(x, x).
 */
@Test public void testDuplicateAnd() {
  // RexProgramBuilder used to translate AND(x, x) to x.
  // Now it translates it to AND(x, x).
  // The optimization of AND(x, x) => x occurs at a higher level.
  final RexProgramBuilder builder = createProg(2);
  final String program = builder.getProgram(true).toString();
  TestUtil.assertEqualsVerbose(
      "(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], expr#3=[1], "
          + "expr#4=[+($t0, $t3)], expr#5=[+($t2, $t4)], "
          + "expr#6=[+($t0, $t0)], expr#7=[>($t2, $t0)], "
          + "a=[$t5], b=[$t6], $condition=[$t7])",
      program);
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RexProgramTest.java


示例16: onMatch

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final Join joinRel = call.rel(0);
  final RelNode otherNode;
  final Calc calc;

  final RelNode leftJoinChild;
  final RelNode rightJoinChild;

  if (call.rel(1) instanceof Calc) {
    otherNode = call.rel(2);
    calc = call.rel(1);
    rightJoinChild = otherNode;
    leftJoinChild = calc.getInput();
  } else {
    otherNode = call.rel(1);
    calc = call.rel(2);
    rightJoinChild = calc.getInput();
    leftJoinChild = otherNode;
  }
  /**
   * Currently not supporting calc which doesnot
   * project star (all the columns of input)
   * or has aggregates.
   */
  if (!isStar(calc.getProgram())
      || calc.getProgram().containsAggs()) {
    return;
  }

  final List<RelDataTypeField> origFields =
      calc.getRowType().getFieldList();
  final int[] adjustments = new int[calc.getProgram().getExprCount()];
  if (rightJoinChild == calc.getInput()) {
    int offset = leftJoinChild.getRowType().getFieldList().size();
    for (int i = 0; i < origFields.size(); i++) {
      adjustments[i] = offset;
    }
  }
  Join newJoinRel =
      joinRel.copy(joinRel.getTraitSet(), joinRel.getCondition(),
          leftJoinChild, rightJoinChild, joinRel.getJoinType(),
          joinRel.isSemiJoinDone());

  RexProgramBuilder topProgramBuilder =
      new RexProgramBuilder(
          joinRel.getRowType(),
          joinRel.getCluster().getRexBuilder());
  topProgramBuilder.addIdentity();
  final RelOptUtil.RexInputConverter rexInputConverter =
      new RelOptUtil.RexInputConverter(calc.getCluster().getRexBuilder(),
          origFields,
          joinRel.getRowType().getFieldList(),
          adjustments);
  if (calc.getProgram().getCondition() != null) {
    RexNode cond =
        calc.getProgram().expandLocalRef(calc.getProgram().getCondition());
    final RexLocalRef rexLocalRef =
        topProgramBuilder.addExpr(cond.accept(rexInputConverter));
    topProgramBuilder.addCondition(rexLocalRef);
  }
  Calc newCalcRel =
      calc.copy(calc.getTraitSet(), newJoinRel, topProgramBuilder.getProgram());

  call.transformTo(newCalcRel);
}
 
开发者ID:qubole,项目名称:quark,代码行数:66,代码来源:JoinCalcTransposeRule.java


示例17: onMatch

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final LogicalProject project = call.rel(0);
  final LogicalCalc calc = call.rel(1);

  // Don't merge a project which contains windowed aggregates onto a
  // calc. That would effectively be pushing a windowed aggregate down
  // through a filter. Transform the project into an identical calc,
  // which we'll have chance to merge later, after the over is
  // expanded.
  final RelOptCluster cluster = project.getCluster();
  RexProgram program =
      RexProgram.create(
          calc.getRowType(),
          project.getProjects(),
          null,
          project.getRowType(),
          cluster.getRexBuilder());
  if (RexOver.containsOver(program)) {
    LogicalCalc projectAsCalc = LogicalCalc.create(calc, program);
    call.transformTo(projectAsCalc);
    return;
  }

  // Create a program containing the project node's expressions.
  final RexBuilder rexBuilder = cluster.getRexBuilder();
  final RexProgramBuilder progBuilder =
      new RexProgramBuilder(
          calc.getRowType(),
          rexBuilder);
  for (Pair<RexNode, String> field : project.getNamedProjects()) {
    progBuilder.addProject(field.left, field.right);
  }
  RexProgram topProgram = progBuilder.getProgram();
  RexProgram bottomProgram = calc.getProgram();

  // Merge the programs together.
  RexProgram mergedProgram =
      RexProgramBuilder.mergePrograms(
          topProgram,
          bottomProgram,
          rexBuilder);
  final LogicalCalc newCalc =
      LogicalCalc.create(calc.getInput(), mergedProgram);
  call.transformTo(newCalc);
}
 
开发者ID:apache,项目名称:calcite,代码行数:46,代码来源:ProjectCalcMergeRule.java


示例18: adjustCondition

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
/**
 * Pulls the project above the semijoin and returns the resulting semijoin
 * condition. As a result, the semijoin condition should be modified such
 * that references to the LHS of a semijoin should now reference the
 * children of the project that's on the LHS.
 *
 * @param project  LogicalProject on the LHS of the semijoin
 * @param semiJoin the semijoin
 * @return the modified semijoin condition
 */
private RexNode adjustCondition(LogicalProject project, SemiJoin semiJoin) {
  // create two RexPrograms -- the bottom one representing a
  // concatenation of the project and the RHS of the semijoin and the
  // top one representing the semijoin condition

  RexBuilder rexBuilder = project.getCluster().getRexBuilder();
  RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
  RelNode rightChild = semiJoin.getRight();

  // for the bottom RexProgram, the input is a concatenation of the
  // child of the project and the RHS of the semijoin
  RelDataType bottomInputRowType =
      SqlValidatorUtil.deriveJoinRowType(
          project.getInput().getRowType(),
          rightChild.getRowType(),
          JoinRelType.INNER,
          typeFactory,
          null,
          semiJoin.getSystemFieldList());
  RexProgramBuilder bottomProgramBuilder =
      new RexProgramBuilder(bottomInputRowType, rexBuilder);

  // add the project expressions, then add input references for the RHS
  // of the semijoin
  for (Pair<RexNode, String> pair : project.getNamedProjects()) {
    bottomProgramBuilder.addProject(pair.left, pair.right);
  }
  int nLeftFields = project.getInput().getRowType().getFieldCount();
  List<RelDataTypeField> rightFields =
      rightChild.getRowType().getFieldList();
  int nRightFields = rightFields.size();
  for (int i = 0; i < nRightFields; i++) {
    final RelDataTypeField field = rightFields.get(i);
    RexNode inputRef =
        rexBuilder.makeInputRef(
            field.getType(), i + nLeftFields);
    bottomProgramBuilder.addProject(inputRef, field.getName());
  }
  RexProgram bottomProgram = bottomProgramBuilder.getProgram();

  // input rowtype into the top program is the concatenation of the
  // project and the RHS of the semijoin
  RelDataType topInputRowType =
      SqlValidatorUtil.deriveJoinRowType(
          project.getRowType(),
          rightChild.getRowType(),
          JoinRelType.INNER,
          typeFactory,
          null,
          semiJoin.getSystemFieldList());
  RexProgramBuilder topProgramBuilder =
      new RexProgramBuilder(
          topInputRowType,
          rexBuilder);
  topProgramBuilder.addIdentity();
  topProgramBuilder.addCondition(semiJoin.getCondition());
  RexProgram topProgram = topProgramBuilder.getProgram();

  // merge the programs and expand out the local references to form
  // the new semijoin condition; it now references a concatenation of
  // the project's child and the RHS of the semijoin
  RexProgram mergedProgram =
      RexProgramBuilder.mergePrograms(
          topProgram,
          bottomProgram,
          rexBuilder);

  return mergedProgram.expandLocalRef(
      mergedProgram.getCondition());
}
 
开发者ID:apache,项目名称:calcite,代码行数:81,代码来源:SemiJoinProjectTransposeRule.java


示例19: rewriteRel

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public void rewriteRel(LogicalCalc rel) {
  // Translate the child.
  final RelNode newInput = getNewForOldRel(rel.getInput());

  final RelOptCluster cluster = rel.getCluster();
  RexProgramBuilder programBuilder =
      new RexProgramBuilder(
          newInput.getRowType(),
          cluster.getRexBuilder());

  // Convert the common expressions.
  final RexProgram program = rel.getProgram();
  final RewriteRexShuttle shuttle = new RewriteRexShuttle();
  for (RexNode expr : program.getExprList()) {
    programBuilder.registerInput(expr.accept(shuttle));
  }

  // Convert the projections.
  final List<Pair<RexNode, String>> flattenedExpList = Lists.newArrayList();
  List<String> fieldNames = rel.getRowType().getFieldNames();
  flattenProjections(new RewriteRexShuttle(),
      program.getProjectList(),
      fieldNames,
      "",
      flattenedExpList);

  // Register each of the new projections.
  for (Pair<RexNode, String> flattenedExp : flattenedExpList) {
    programBuilder.addProject(flattenedExp.left, flattenedExp.right);
  }

  // Translate the condition.
  final RexLocalRef conditionRef = program.getCondition();
  if (conditionRef != null) {
    programBuilder.addCondition(
        new RexLocalRef(
            getNewForOldInput(conditionRef.getIndex()),
            conditionRef.getType()));
  }

  RexProgram newProgram = programBuilder.getProgram();

  // Create a new calc relational expression.
  LogicalCalc newRel = LogicalCalc.create(newInput, newProgram);
  setNewForOldRel(rel, newRel);
}
 
开发者ID:apache,项目名称:calcite,代码行数:47,代码来源:RelStructuredTypeFlattener.java


示例20: compile

import org.apache.calcite.rex.RexProgramBuilder; //导入依赖的package包/类
public Scalar compile(List<RexNode> nodes, RelDataType inputRowType) {
  final RexProgramBuilder programBuilder =
      new RexProgramBuilder(inputRowType, rexBuilder);
  for (RexNode node : nodes) {
    programBuilder.addProject(node, null);
  }
  final RexProgram program = programBuilder.getProgram();

  final BlockBuilder builder = new BlockBuilder();
  final ParameterExpression context_ =
      Expressions.parameter(Context.class, "context");
  final ParameterExpression outputValues_ =
      Expressions.parameter(Object[].class, "outputValues");
  final JavaTypeFactoryImpl javaTypeFactory =
      new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem());

  // public void execute(Context, Object[] outputValues)
  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 baz(context_, outputValues_, builder.toBlock());
}
 
开发者ID:apache,项目名称:calcite,代码行数:47,代码来源:JaninoRexCompiler.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RendererHelper类代码示例发布时间:2022-05-22
下一篇:
Java CanvasGameContainer类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap