Java Code Examples for org.apache.calcite.DataContext#ROOT

The following examples show how to use org.apache.calcite.DataContext#ROOT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveRexExecutorImpl.java    From marble with Apache License 2.0 5 votes vote down vote up
private String compile(RexBuilder rexBuilder, List<RexNode> constExps,
    RexToLixTranslator.InputGetter getter, RelDataType rowType) {
  final RexProgramBuilder programBuilder =
      new RexProgramBuilder(rowType, rexBuilder);
  for (RexNode node : constExps) {
    programBuilder.addProject(
        node, "c" + programBuilder.getProjectList().size());
  }
  final JavaTypeFactoryImpl javaTypeFactory =
      new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem());
  final BlockBuilder blockBuilder = new BlockBuilder();
  final ParameterExpression root0_ =
      Expressions.parameter(Object.class, "root0");
  final ParameterExpression root_ = DataContext.ROOT;
  blockBuilder.add(
      Expressions.declare(
          Modifier.FINAL, root_,
          Expressions.convert_(root0_, DataContext.class)));
  final SqlConformance conformance = SqlConformanceEnum.HIVE;
  final RexProgram program = programBuilder.getProgram();
  final List<Expression> expressions =
      RexToLixTranslator.translateProjects(program, javaTypeFactory,
          conformance, blockBuilder, null, root_, getter, null);
  blockBuilder.add(
      Expressions.return_(null,
          Expressions.newArrayInit(Object[].class, expressions)));
  final MethodDeclaration methodDecl =
      Expressions.methodDecl(Modifier.PUBLIC, Object[].class,
          BuiltInMethod.FUNCTION1_APPLY.method.getName(),
          ImmutableList.of(root0_), blockBuilder.toBlock());
  String code = Expressions.toString(methodDecl);
  if (CalcitePrepareImpl.DEBUG) {
    Util.debugCode(System.out, code);
  }
  return code;
}
 
Example 2
Source File: RexToLixTranslator.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a translator for translating aggregate functions. */
public static RexToLixTranslator forAggregation(JavaTypeFactory typeFactory,
    BlockBuilder list, InputGetter inputGetter, SqlConformance conformance) {
  final ParameterExpression root = DataContext.ROOT;
  return new RexToLixTranslator(null, typeFactory, root, inputGetter, list,
      new RexBuilder(typeFactory), conformance, null);
}
 
Example 3
Source File: RexToLixTranslator.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static Expression translateCondition(RexProgram program,
    JavaTypeFactory typeFactory, BlockBuilder list, InputGetter inputGetter,
    Function1<String, InputGetter> correlates, SqlConformance conformance) {
  if (program.getCondition() == null) {
    return RexImpTable.TRUE_EXPR;
  }
  final ParameterExpression root = DataContext.ROOT;
  RexToLixTranslator translator =
      new RexToLixTranslator(program, typeFactory, root, inputGetter, list,
          new RexBuilder(typeFactory), conformance, null);
  translator = translator.setCorrelates(correlates);
  return translator.translate(
      program.getCondition(),
      RexImpTable.NullAs.FALSE);
}
 
Example 4
Source File: RexExecutorImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static String compile(RexBuilder rexBuilder, List<RexNode> constExps,
    RexToLixTranslator.InputGetter getter, RelDataType rowType) {
  final RexProgramBuilder programBuilder =
      new RexProgramBuilder(rowType, rexBuilder);
  for (RexNode node : constExps) {
    programBuilder.addProject(
        node, "c" + programBuilder.getProjectList().size());
  }
  final JavaTypeFactoryImpl javaTypeFactory =
      new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem());
  final BlockBuilder blockBuilder = new BlockBuilder();
  final ParameterExpression root0_ =
      Expressions.parameter(Object.class, "root0");
  final ParameterExpression root_ = DataContext.ROOT;
  blockBuilder.add(
      Expressions.declare(
          Modifier.FINAL, root_,
          Expressions.convert_(root0_, DataContext.class)));
  final SqlConformance conformance = SqlConformanceEnum.DEFAULT;
  final RexProgram program = programBuilder.getProgram();
  final List<Expression> expressions =
      RexToLixTranslator.translateProjects(program, javaTypeFactory,
          conformance, blockBuilder, null, root_, getter, null);
  blockBuilder.add(
      Expressions.return_(null,
          Expressions.newArrayInit(Object[].class, expressions)));
  final MethodDeclaration methodDecl =
      Expressions.methodDecl(Modifier.PUBLIC, Object[].class,
          BuiltInMethod.FUNCTION1_APPLY.method.getName(),
          ImmutableList.of(root0_), blockBuilder.toBlock());
  String code = Expressions.toString(methodDecl);
  if (CalciteSystemProperty.DEBUG.value()) {
    Util.debugCode(System.out, code);
  }
  return code;
}
 
Example 5
Source File: JavaRelImplementor.java    From calcite with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the expression used to access
 * {@link org.apache.calcite.DataContext}.
 *
 * @return expression used to access {@link org.apache.calcite.DataContext}.
 */
public ParameterExpression getRootExpression() {
  return DataContext.ROOT;
}