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

Java RexToLixTranslator类代码示例

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

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



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

示例1: createImplementor

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
private static CallImplementor createImplementor(final Method method) {
  return RexImpTable.createImplementor(
      new ReflectiveCallNotNullImplementor(method) {
        public Expression implement(RexToLixTranslator translator,
            RexCall call, List<Expression> translatedOperands) {
          Expression expr = super.implement(translator, call,
              translatedOperands);
          final Class<?> returnType = method.getReturnType();
          if (QueryableTable.class.isAssignableFrom(returnType)) {
            Expression queryable = Expressions.call(
                Expressions.convert_(expr, QueryableTable.class),
                BuiltInMethod.QUERYABLE_TABLE_AS_QUERYABLE.method,
                Expressions.call(DataContext.ROOT,
                    BuiltInMethod.DATA_CONTEXT_GET_QUERY_PROVIDER.method),
                Expressions.constant(null, SchemaPlus.class),
                Expressions.constant(call.getOperator().getName(), String.class));
            expr = Expressions.call(queryable,
                BuiltInMethod.QUERYABLE_AS_ENUMERABLE.method);
          } else {
            expr = Expressions.call(expr,
                BuiltInMethod.SCANNABLE_TABLE_SCAN.method, DataContext.ROOT);
          }
          return expr;
        }
      }, NullPolicy.ANY, false);
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:TableFunctionImpl.java


示例2: field

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


示例3: getExpression

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


示例4: compileToBlock

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


示例5: visitLiteral

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
@Override public String visitLiteral(RexLiteral literal) {
  if (literal.getValue() == null) {
    return "null";
  }
  return "{$literal: "
      + RexToLixTranslator.translateLiteral(literal, literal.getType(),
          typeFactory, RexImpTable.NullAs.NOT_POSSIBLE)
      + "}";
}
 
开发者ID:apache,项目名称:calcite,代码行数:10,代码来源:MongoRules.java


示例6: visitLiteral

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
@Override public String visitLiteral(RexLiteral literal) {
  if (literal.getValue() == null) {
    return "null";
  }
  return "\"literal\":\""
    + RexToLixTranslator.translateLiteral(literal, literal.getType(),
      typeFactory, RexImpTable.NullAs.NOT_POSSIBLE)
    + "\"";
}
 
开发者ID:apache,项目名称:calcite,代码行数:10,代码来源:ElasticsearchRules.java


示例7: compile

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
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 List<Expression> expressions =
      RexToLixTranslator.translateProjects(programBuilder.getProgram(),
      javaTypeFactory, 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;
}
 
开发者ID:apache,项目名称:calcite,代码行数:35,代码来源:RexExecutorImpl.java


示例8: reduce

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
/**
 * Do constant reduction using generated code.
 */
public void reduce(RexBuilder rexBuilder, List<RexNode> constExps,
    List<RexNode> reducedValues) {
  final String code = compile(rexBuilder, constExps,
      new RexToLixTranslator.InputGetter() {
        public Expression field(BlockBuilder list, int index,
            Type storageType) {
          throw new UnsupportedOperationException();
        }
      });

  final RexExecutable executable = new RexExecutable(code, constExps);
  executable.setDataContext(dataContext);
  executable.reduce(rexBuilder, constExps, reducedValues);
}
 
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:RexExecutorImpl.java


示例9: getImplementor

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
@Override public CallImplementor getImplementor() {
  return new CallImplementor() {
    public Expression implement(RexToLixTranslator translator, RexCall call, NullAs nullAs) {
      Method lookupMethod =
          Types.lookupMethod(Smalls.AllTypesFunction.class,
              "arrayAppendFun", List.class, Integer.class);
      return Expressions.call(lookupMethod,
          translator.translateList(call.getOperands(), nullAs));
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:12,代码来源:UdfTest.java


示例10: toRex

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
public RexNode toRex(Expression expression) {
  switch (expression.getNodeType()) {
  case MemberAccess:
    // Case-sensitive name match because name was previously resolved.
    return rexBuilder.makeFieldAccess(
        toRex(
            ((MemberExpression) expression).expression),
        ((MemberExpression) expression).field.getName(),
        true);
  case GreaterThan:
    return binary(expression, SqlStdOperatorTable.GREATER_THAN);
  case LessThan:
    return binary(expression, SqlStdOperatorTable.LESS_THAN);
  case Parameter:
    return parameter((ParameterExpression) expression);
  case Call:
    MethodCallExpression call = (MethodCallExpression) expression;
    SqlOperator operator =
        RexToLixTranslator.JAVA_TO_SQL_METHOD_MAP.get(call.method);
    if (operator != null) {
      return rexBuilder.makeCall(
          type(call),
          operator,
          toRex(
              Expressions.<Expression>list()
                  .appendIfNotNull(call.targetExpression)
                  .appendAll(call.expressions)));
    }
    throw new RuntimeException(
        "Could translate call to method " + call.method);
  case Constant:
    final ConstantExpression constant =
        (ConstantExpression) expression;
    Object value = constant.value;
    if (value instanceof Number) {
      Number number = (Number) value;
      if (value instanceof Double || value instanceof Float) {
        return rexBuilder.makeApproxLiteral(
            BigDecimal.valueOf(number.doubleValue()));
      } else if (value instanceof BigDecimal) {
        return rexBuilder.makeExactLiteral((BigDecimal) value);
      } else {
        return rexBuilder.makeExactLiteral(
            BigDecimal.valueOf(number.longValue()));
      }
    } else if (value instanceof Boolean) {
      return rexBuilder.makeLiteral((Boolean) value);
    } else {
      return rexBuilder.makeLiteral(constant.toString());
    }
  default:
    throw new UnsupportedOperationException(
        "unknown expression type " + expression.getNodeType() + " "
        + expression);
  }
}
 
开发者ID:apache,项目名称:kylin,代码行数:57,代码来源:CalcitePrepareImpl.java


示例11: implementSpark

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
public Result implementSpark(Implementor implementor) {
/*
            return Linq4j.asSpark(
                new Object[][] {
                    new Object[] {1, 2},
                    new Object[] {3, 4}
                });
*/
      final JavaTypeFactory typeFactory =
          (JavaTypeFactory) getCluster().getTypeFactory();
      final BlockBuilder builder = new BlockBuilder();
      final PhysType physType =
          PhysTypeImpl.of(implementor.getTypeFactory(),
              getRowType(),
              JavaRowFormat.CUSTOM);
      final Type rowClass = physType.getJavaRowType();

      final List<Expression> expressions = new ArrayList<Expression>();
      final List<RelDataTypeField> fields = rowType.getFieldList();
      for (List<RexLiteral> tuple : tuples) {
        final List<Expression> literals = new ArrayList<Expression>();
        for (Pair<RelDataTypeField, RexLiteral> pair
            : Pair.zip(fields, tuple)) {
          literals.add(
              RexToLixTranslator.translateLiteral(
                  pair.right,
                  pair.left.getType(),
                  typeFactory,
                  RexImpTable.NullAs.NULL));
        }
        expressions.add(physType.record(literals));
      }
      builder.add(
          Expressions.return_(null,
              Expressions.call(SparkMethod.ARRAY_TO_RDD.method,
                  Expressions.call(SparkMethod.GET_SPARK_CONTEXT.method,
                      implementor.getRootExpression()),
                  Expressions.newArrayInit(Primitive.box(rowClass),
                      expressions))));
      return implementor.result(physType, builder.toBlock());
    }
 
开发者ID:apache,项目名称:calcite,代码行数:42,代码来源:SparkRules.java


示例12: rowTranslator

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
public final RexToLixTranslator rowTranslator() {
  return rowTranslator(
      computeIndex(Expressions.constant(0),
          WinAggImplementor.SeekType.AGG_INDEX));
}
 
开发者ID:apache,项目名称:calcite,代码行数:6,代码来源:WinAggAddContextImpl.java


示例13: rowTranslator

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
public RexToLixTranslator rowTranslator(Expression rowIndex) {
  return getFrame().rowTranslator(rowIndex)
      .setNullable(currentNullables());
}
 
开发者ID:apache,项目名称:calcite,代码行数:5,代码来源:WinAggResultContextImpl.java


示例14: implement

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的package包/类
public Expression implement(RexToLixTranslator translator,
    RexCall call, List<Expression> operands) {
  return Expressions.call(GET_COMPLETION_HINTS,
      Iterables.concat(Collections.singleton(ADVISOR), operands));
}
 
开发者ID:apache,项目名称:calcite,代码行数:6,代码来源:SqlAdvisorGetHintsFunction.java


示例15: compile

import org.apache.calcite.adapter.enumerable.RexToLixTranslator; //导入依赖的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.adapter.enumerable.RexToLixTranslator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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