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

Java BlockStatement类代码示例

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

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



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

示例1: finalizeExpression

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
private String finalizeExpression(BlockStatement blockStatement, RelDataType inputRowType)
{
  String s = Expressions.toString(blockStatement.statements.get(0));
  int idx = 0;
  for (RelDataTypeField field : inputRowType.getFieldList()) {
    String fieldName = OperatorUtils.getFieldName(field);
    s = s.replaceAll(String.format("inputValues\\[%d\\]", idx++), "\\{\\$." + Matcher.quoteReplacement(fieldName) + "\\}");
  }

  return s.substring(0, s.length() - 2);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:12,代码来源:ExpressionCompiler.java


示例2: compileToBlock

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


示例3: baz

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


示例4: toRexList

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public List<RexNode> toRexList(BlockStatement statement) {
  final List<Expression> simpleList = simpleList(statement);
  final List<RexNode> list = new ArrayList<>();
  for (Expression expression1 : simpleList) {
    list.add(toRex(expression1));
  }
  return list;
}
 
开发者ID:apache,项目名称:kylin,代码行数:9,代码来源:CalcitePrepareImpl.java


示例5: simpleList

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
private static List<Expression> simpleList(BlockStatement statement) {
  Expression simple = Blocks.simple(statement);
  if (simple instanceof NewExpression) {
    NewExpression newExpression = (NewExpression) simple;
    return newExpression.arguments;
  } else {
    return Collections.singletonList(simple);
  }
}
 
开发者ID:apache,项目名称:kylin,代码行数:10,代码来源:CalcitePrepareImpl.java


示例6: checkBlockBuilder

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


示例7: testBlockBuilder2

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
@Test public void testBlockBuilder2() {
  BlockBuilder statements = new BlockBuilder();
  Expression element =
      statements.append(
          "element", Expressions.constant(null));
  Expression comparator =
      statements.append(
          "comparator", Expressions.constant(null, Comparator.class));
  Expression treeSet =
      statements.append(
          "treeSet",
          Expressions.new_(
              TreeSet.class,
              Arrays.asList(comparator)));
  statements.add(
      Expressions.return_(
          null,
          Expressions.call(
              treeSet,
              "add",
              element)));
  BlockStatement expression = statements.toBlock();
  final String expected = "{\n"
      + "  final java.util.TreeSet treeSet = new java.util.TreeSet(\n"
      + "    (java.util.Comparator) null);\n"
      + "  return treeSet.add(null);\n"
      + "}\n";
  assertThat(Expressions.toString(expression), is(expected));
  expression.accept(new Shuttle());
}
 
开发者ID:apache,项目名称:calcite,代码行数:31,代码来源:ExpressionTest.java


示例8: overridingMethodDecl

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
/** Declares a method that overrides another method. */
public static MethodDeclaration overridingMethodDecl(Method method,
    Iterable<ParameterExpression> parameters,
    BlockStatement body) {
  return Expressions.methodDecl(
      method.getModifiers() & ~Modifier.ABSTRACT,
      method.getReturnType(),
      method.getName(),
      parameters,
      body);
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:EnumUtils.java


示例9: implementResult

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public final Expression implementResult(AggContext info,
    final AggResultContext result) {
  if (!needTrackEmptySet) {
    return RexToLixTranslator.convert(
        implementNotNullResult(info, result), info.returnType());
  }
  String tmpName = result.accumulator().isEmpty()
      ? "ar"
      : (result.accumulator().get(0) + "$Res");
  ParameterExpression res = Expressions.parameter(0, info.returnType(),
      result.currentBlock().newName(tmpName));

  List<Expression> acc = result.accumulator();
  final BlockBuilder thenBlock = result.nestBlock();
  Expression nonNull = RexToLixTranslator.convert(
      implementNotNullResult(info, result), info.returnType());
  result.exitBlock();
  thenBlock.add(Expressions.statement(Expressions.assign(res, nonNull)));
  BlockStatement thenBranch = thenBlock.toBlock();
  Expression seenNotNullRows =
      trackNullsPerRow
      ? acc.get(acc.size() - 1)
      : ((WinAggResultContext) result).hasRows();

  if (thenBranch.statements.size() == 1) {
    return Expressions.condition(seenNotNullRows,
        nonNull, RexImpTable.getDefaultValue(res.getType()));
  }
  result.currentBlock().add(Expressions.declare(0, res, null));
  result.currentBlock().add(
      Expressions.ifThenElse(seenNotNullRows,
          thenBranch,
          Expressions.statement(
              Expressions.assign(res,
                  RexImpTable.getDefaultValue(res.getType())))));
  return res;
}
 
开发者ID:apache,项目名称:calcite,代码行数:38,代码来源:StrictAggImplementor.java


示例10: createSamzaExpressionFromCalcite

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
/**
 * This method takes the java statement block, inputs, outputs needed by the statement block to create an object
 * of class that implements the interface {@link Expression}
 *
 * for e.g.
 *   Query : select id from profile
 *      where profile table has relational schema with id(NUMBER) and name(VARCHAR) columns.
 *    This query will result in the following relational plan
 *      LogicalProject(id=[$1])
 *        LogicalTableScan(table=[[profile]])
 *
 *
 *    And the corresponding expressions are
 *       inputs : EnumerableTableScan (Which is the output of LogicalTableScan)
 *       nodes : [$1] Which essentially means take pick the first column from the input
 *
 *    This expression corresponding to the logicalProject "[$1]" gets converted into a java statement block
 *    {
 *      outputValues[0] = (Integer) inputValues[1];
 *    }
 *
 *    This method converts this statement block into an equivalent {@link Expression} object whose execute methods
 *    execute the above java statement block
 *
 */
static org.apache.samza.sql.data.Expression createSamzaExpressionFromCalcite(ParameterExpression executionContext,
    ParameterExpression dataContext, ParameterExpression inputValues, ParameterExpression outputValues,
    BlockStatement block) {
  final List<MemberDeclaration> declarations = Lists.newArrayList();

  // public void execute(Object[] inputValues, Object[] outputValues)
  declarations.add(
      Expressions.methodDecl(Modifier.PUBLIC, void.class, SamzaBuiltInMethod.EXPR_EXECUTE2.method.getName(),
          ImmutableList.of(executionContext, dataContext, inputValues, outputValues), block));

  final ClassDeclaration classDeclaration = Expressions.classDecl(Modifier.PUBLIC, "SqlExpression", null,
      ImmutableList.<Type>of(org.apache.samza.sql.data.Expression.class), declarations);
  String s = Expressions.toString(declarations, "\n", false);

  log.info("Generated code for expression: {}", s);

  try {
    return getExpression(classDeclaration, s);
  } catch (Exception e) {
    throw new SamzaException("Expression compilation failure.", e);
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:48,代码来源:RexToJavaCompiler.java


示例11: toRex

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public RexNode toRex(BlockStatement statement) {
  return toRex(Blocks.simple(statement));
}
 
开发者ID:apache,项目名称:kylin,代码行数:4,代码来源:CalcitePrepareImpl.java


示例12: result

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public SparkRel.Result result(PhysType physType,
    BlockStatement blockStatement) {
  return new SparkRel.Result(physType, blockStatement);
}
 
开发者ID:apache,项目名称:calcite,代码行数:5,代码来源:SparkToEnumerableConverter.java


示例13: Result

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public Result(PhysType physType, BlockStatement block) {
  this.physType = physType;
  this.block = block;
}
 
开发者ID:apache,项目名称:calcite,代码行数:5,代码来源:SparkRel.java


示例14: testBlockBuilder3

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
@Test public void testBlockBuilder3() {
/*
    int a = 1;
    int b = a + 2;
    int c = a + 3;
    int d = a + 4;
    int e = {
      int b = a + 3;
      foo(b);
    }
    bar(a, b, c, d, e);
*/
    BlockBuilder builder0 = new BlockBuilder();
    final Expression a = builder0.append("_a", Expressions.constant(1));
    final Expression b =
        builder0.append("_b", Expressions.add(a, Expressions.constant(2)));
    final Expression c =
        builder0.append("_c", Expressions.add(a, Expressions.constant(3)));
    final Expression d =
        builder0.append("_d", Expressions.add(a, Expressions.constant(4)));

    BlockBuilder builder1 = new BlockBuilder();
    final Expression b1 =
        builder1.append("_b", Expressions.add(a, Expressions.constant(3)));
    builder1.add(
        Expressions.statement(
            Expressions.call(ExpressionTest.class, "foo", b1)));
    final Expression e = builder0.append("e", builder1.toBlock());
    builder0.add(
        Expressions.statement(
            Expressions.call(ExpressionTest.class, "bar", a, b, c, d, e)));
    // With the bug in BlockBuilder.append(String, BlockExpression),
    //    bar(1, _b, _c, _d, foo(_d));
    // Correct result is
    //    bar(1, _b, _c, _d, foo(_c));
    // because _c has the same expression (a + 3) as inner b.
    BlockStatement expression = builder0.toBlock();
    assertEquals(
        "{\n"
            + "  final int _b = 1 + 2;\n"
            + "  final int _c = 1 + 3;\n"
            + "  final int _d = 1 + 4;\n"
            + "  org.apache.calcite.linq4j.test.ExpressionTest.bar(1, _b, _c, _d, org.apache.calcite.linq4j.test.ExpressionTest.foo(_c));\n"
            + "}\n",
        Expressions.toString(expression));
    expression.accept(new Shuttle());
  }
 
开发者ID:apache,项目名称:calcite,代码行数:48,代码来源:ExpressionTest.java


示例15: optimizeExpression

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public static BlockStatement optimizeExpression(Expression expr) {
  return optimizeStatement(Expressions.return_(null, expr));
}
 
开发者ID:apache,项目名称:calcite,代码行数:4,代码来源:BlockBuilderBase.java


示例16: result

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public EnumerableRel.Result result(PhysType physType, BlockStatement block) {
  return new EnumerableRel.Result(
      block, physType, ((PhysTypeImpl) physType).format);
}
 
开发者ID:apache,项目名称:calcite,代码行数:5,代码来源:EnumerableRelImplementor.java


示例17: implementResult

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public Expression implementResult(AggContext info,
    AggResultContext result) {
  WinAggResultContext winResult = (WinAggResultContext) result;

  List<RexNode> rexArgs = winResult.rexArguments();

  ParameterExpression res = Expressions.parameter(0, info.returnType(),
      result.currentBlock().newName(isLead ? "lead" : "lag"));

  Expression offset;
  RexToLixTranslator currentRowTranslator =
      winResult.rowTranslator(
          winResult.computeIndex(Expressions.constant(0), SeekType.SET));
  if (rexArgs.size() >= 2) {
    // lead(x, offset) or lead(x, offset, default)
    offset = currentRowTranslator.translate(
        rexArgs.get(1), int.class);
  } else {
    offset = Expressions.constant(1);
  }
  if (!isLead) {
    offset = Expressions.negate(offset);
  }
  Expression dstIndex = winResult.computeIndex(offset, SeekType.SET);

  Expression rowInRange = winResult.rowInPartition(dstIndex);

  BlockBuilder thenBlock = result.nestBlock();
  Expression lagResult = winResult.rowTranslator(dstIndex).translate(
      rexArgs.get(0), res.type);
  thenBlock.add(Expressions.statement(Expressions.assign(res, lagResult)));
  result.exitBlock();
  BlockStatement thenBranch = thenBlock.toBlock();

  Expression defaultValue = rexArgs.size() == 3
      ? currentRowTranslator.translate(rexArgs.get(2), res.type)
      : getDefaultValue(res.type);

  result.currentBlock().add(Expressions.declare(0, res, null));
  result.currentBlock().add(
      Expressions.ifThenElse(rowInRange, thenBranch,
          Expressions.statement(Expressions.assign(res, defaultValue))));
  return res;
}
 
开发者ID:apache,项目名称:calcite,代码行数:45,代码来源:RexImpTable.java


示例18: Result

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public Result(BlockStatement block, PhysType physType,
    JavaRowFormat format) {
  this.block = block;
  this.physType = physType;
  this.format = format;
}
 
开发者ID:apache,项目名称:calcite,代码行数:7,代码来源:EnumerableRel.java


示例19: result

import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
abstract Result result(PhysType physType, BlockStatement blockStatement); 
开发者ID:apache,项目名称:calcite,代码行数:2,代码来源:SparkRel.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java AsyncServerSocket类代码示例发布时间:2022-05-22
下一篇:
Java SimpleValueNames类代码示例发布时间: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