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


Java RexLiteral类代码示例

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


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

示例1: verifyRowType

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private static void verifyRowType(final ImmutableList<ImmutableList<RexLiteral>> tuples, RelDataType rowType){
    for (List<RexLiteral> tuple : tuples) {
      assert (tuple.size() == rowType.getFieldCount());

      for (Pair<RexLiteral, RelDataTypeField> pair : Pair.zip(tuple, rowType.getFieldList())) {
        RexLiteral literal = (RexLiteral) pair.left;
        RelDataType fieldType = ((RelDataTypeField) pair.right).getType();

        if ((!(RexLiteral.isNullLiteral(literal)))
            && (!(SqlTypeUtil.canAssignFrom(fieldType, literal.getType())))) {
          throw new AssertionError("to " + fieldType + " from " + literal);
        }
      }
    }

}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:17,代码来源:DrillValuesRel.java

示例2: convertToJsonNode

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private static JsonNode convertToJsonNode(RelDataType rowType, ImmutableList<ImmutableList<RexLiteral>> tuples) throws IOException{
  TokenBuffer out = new TokenBuffer(MAPPER.getFactory().getCodec(), false);
  JsonOutput json = new ExtendedJsonOutput(out);
  json.writeStartArray();
  String[] fields = rowType.getFieldNames().toArray(new String[rowType.getFieldCount()]);

  for(List<RexLiteral> row : tuples){
    json.writeStartObject();
    int i =0;
    for(RexLiteral field : row){
      json.writeFieldName(fields[i]);
      writeLiteral(field, json);
      i++;
    }
    json.writeEndObject();
  }
  json.writeEndArray();
  json.flush();
  return out.asParser().readValueAsTree();
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:21,代码来源:DrillValuesRel.java

示例3: onMatch

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
  final LimitPrel limit = (LimitPrel) call.rel(0);
  final SingleMergeExchangePrel smex = (SingleMergeExchangePrel) call.rel(1);
  final SortPrel sort = (SortPrel) call.rel(2);

  // First offset to include into results (inclusive). Null implies it is starting from offset 0
  int offset = limit.getOffset() != null ? Math.max(0, RexLiteral.intValue(limit.getOffset())) : 0;
  int fetch = limit.getFetch() != null?  Math.max(0, RexLiteral.intValue(limit.getFetch())) : 0;

  final TopNPrel topN = new TopNPrel(limit.getCluster(), sort.getTraitSet(), sort.getInput(), offset + fetch, sort.getCollation());
  final LimitPrel newLimit = new LimitPrel(limit.getCluster(), limit.getTraitSet(),
      new SingleMergeExchangePrel(smex.getCluster(), smex.getTraitSet(), topN, sort.getCollation()),
      limit.getOffset(), limit.getFetch());

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

示例4: onMatch

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
  final LimitPrel limit = (LimitPrel) call.rel(0);
  final UnionExchangePrel unionExchangePrel = (UnionExchangePrel) call.rel(1);

  RelNode child = unionExchangePrel.getInput();

  final int offset = limit.getOffset() != null ? Math.max(0, RexLiteral.intValue(limit.getOffset())) : 0;
  final int fetch = Math.max(0, RexLiteral.intValue(limit.getFetch()));

  // child Limit uses conservative approach:  use offset 0 and fetch = parent limit offset + parent limit fetch.
  final RexNode childFetch = limit.getCluster().getRexBuilder().makeExactLiteral(BigDecimal.valueOf(offset + fetch));

  final RelNode limitUnderExchange = new LimitPrel(child.getCluster(), child.getTraitSet(), child, null, childFetch);
  final RelNode newUnionExch = new UnionExchangePrel(unionExchangePrel.getCluster(), unionExchangePrel.getTraitSet(), limitUnderExchange);
  final RelNode limitAboveExchange = new LimitPrel(limit.getCluster(), limit.getTraitSet(), newUnionExch, limit.getOffset(), limit.getFetch(), true);

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

示例5: visitCall

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public PathSegment visitCall(RexCall call) {
  if ("ITEM".equals(call.getOperator().getName())) {
    PathSegment mapOrArray = call.operands.get(0).accept(this);
    if (mapOrArray != null) {
      if (call.operands.get(1) instanceof RexLiteral) {
        return mapOrArray.cloneWithNewChild(convertLiteral((RexLiteral) call.operands.get(1)));
      }
      return mapOrArray;
    }
  } else {
    for (RexNode operand : call.operands) {
      addColumn(operand.accept(this));
    }
  }
  return null;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:18,代码来源:PrelUtil.java

示例6: toDrill

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
protected LogicalExpression toDrill(AggregateCall call, List<String> fn) {
  DrillParseContext context = new DrillParseContext(PrelUtil.getSettings(getCluster()));

  List<LogicalExpression> args = Lists.newArrayList();
  for (Integer i : call.getArgList()) {
    final int indexInConstants = i - fn.size();
    if (i < fn.size()) {
      args.add(new FieldReference(fn.get(i)));
    } else {
      final RexLiteral constant = constants.get(indexInConstants);
      LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), constant);
      args.add(expr);
    }
  }

  // for count(1).
  if (args.isEmpty()) {
    args.add(new ValueExpressions.LongExpression(1l));
  }

  return new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:23,代码来源:WindowPrel.java

示例7: getPhysicalOperator

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
  Prel child = (Prel) this.getInput();

  PhysicalOperator childPOP = child.getPhysicalOperator(creator);

  // First offset to include into results (inclusive). Null implies it is starting from offset 0
  int first = offset != null ? Math.max(0, RexLiteral.intValue(offset)) : 0;

  // Last offset to stop including into results (exclusive), translating fetch row counts into an offset.
  // Null value implies including entire remaining result set from first offset
  Integer last = fetch != null ? Math.max(0, RexLiteral.intValue(fetch)) + first : null;

  Limit limit = new Limit(childPOP, first, last);
  return creator.addMetadata(this, limit);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:17,代码来源:LimitPrel.java

示例8: visitCall

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public Boolean visitCall(RexCall call) {
  if (call.getOperator() == SqlStdOperatorTable.ITEM) {
    final RexNode op0 = call.getOperands().get(0);
    final RexNode op1 = call.getOperands().get(1);

    if (op0 instanceof RexInputRef &&
        op1 instanceof RexLiteral && ((RexLiteral) op1).getTypeName() == SqlTypeName.CHAR) {
      return true;
    } else if (op0 instanceof RexCall &&
        op1 instanceof RexLiteral && ((RexLiteral) op1).getTypeName() == SqlTypeName.CHAR) {
      return op0.accept(this);
    }
  }

  return false;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:18,代码来源:DrillProjectRelBase.java

示例9: verifyRowType

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private static void verifyRowType(final ImmutableList<ImmutableList<RexLiteral>> tuples, RelDataType rowType){
    for (List<RexLiteral> tuple : tuples) {
      assert (tuple.size() == rowType.getFieldCount());

      for (Pair<RexLiteral, RelDataTypeField> pair : Pair.zip(tuple, rowType.getFieldList())) {
        RexLiteral literal = pair.left;
        RelDataType fieldType = pair.right.getType();

        if ((!(RexLiteral.isNullLiteral(literal)))
            && (!(SqlTypeUtil.canAssignFrom(fieldType, literal.getType())))) {
          throw new AssertionError("to " + fieldType + " from " + literal);
        }
      }
    }

}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:ValuesRel.java

示例10: toExpr

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
protected LogicalExpression toExpr(AggregateCall call, List<String> fn) {
  ParseContext context = new ParseContext(PrelUtil.getSettings(getCluster()));

  List<LogicalExpression> args = Lists.newArrayList();
  for (Integer i : call.getArgList()) {
    final int indexInConstants = i - fn.size();
    if (i < fn.size()) {
      args.add(new FieldReference(fn.get(i)));
    } else {
      final RexLiteral constant = constants.get(indexInConstants);
      LogicalExpression expr = RexToExpr.toExpr(context, getInput(), constant);
      args.add(expr);
    }
  }

  // for count(1).
  if (args.isEmpty()) {
    args.add(new ValueExpressions.LongExpression(1l));
  }

  return new FunctionCall(call.getAggregation().getName().toLowerCase(), args);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:WindowPrel.java

示例11: matches

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public boolean matches(RelOptRuleCall call) {
  final LimitPrel limit = call.rel(0);
  final ElasticsearchIntermediatePrel intermediatePrel = call.rel(1);

  if (intermediatePrel.hasTerminalPrel()) {
    return false;
  }

  // TODO: this can probably be supported in many cases.
  if (limit.getOffset() != null && RexLiteral.intValue(limit.getOffset()) != 0) {
    return false;
  }

  final PlannerSettings plannerSettings = PrelUtil.getPlannerSettings(limit.getCluster().getPlanner());
  if (intermediatePrel.contains(ElasticsearchSample.class)
      && limit.getFetch() != null
      && RexLiteral.intValue(limit.getFetch()) >= SampleCrel.getSampleSizeAndSetMinSampleSize(plannerSettings, ElasticSampleRule.SAMPLE_SIZE_DENOMINATOR)) {
    return false;
  }

  return true;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:24,代码来源:ElasticLimitRule.java

示例12: render

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override
public FunctionRender render(FunctionRenderer renderer, RexCall call) {
  checkArity(call, 3);

  RexNode op0 = call.getOperands().get(0);
  if (op0 instanceof RexLiteral) {
    final FunctionRender trimChar = call.getOperands().get(1).accept(renderer.getVisitor());
    final FunctionRender inputStr = call.getOperands().get(2).accept(renderer.getVisitor());
    if (TRIM_CHAR.equals(trimChar.getScript())) {
      if (((RexLiteral) op0).getValue() == SqlTrimFunction.Flag.BOTH) {
        return new FunctionRender(inputStr.getScript() + ".trim()", inputStr.getNulls());
      }
    }
  }
  throw new UnsupportedOperationException("incorrect arguments for trim function");
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:TrimFunction.java

示例13: planValues

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private PlannerOp planValues(EnumerableValues op) {

        List<List<CompiledSQLExpression>> tuples = new ArrayList<>(op.getTuples().size());
        RelDataType rowType = op.getRowType();
        List<RelDataTypeField> fieldList = rowType.getFieldList();

        Column[] columns = new Column[fieldList.size()];
        for (ImmutableList<RexLiteral> tuple : op.getTuples()) {
            List<CompiledSQLExpression> row = new ArrayList<>(tuple.size());
            for (RexLiteral node : tuple) {
                CompiledSQLExpression exp = SQLExpressionCompiler.compileExpression(node);
                row.add(exp);
            }
            tuples.add(row);
        }
        int i = 0;
        String[] fieldNames = new String[fieldList.size()];
        for (RelDataTypeField field : fieldList) {
            Column col = Column.column(field.getName(), convertToHerdType(field.getType()));
            fieldNames[i] = field.getName();
            columns[i++] = col;
        }
        return new ValuesOp(manager.getNodeId(), fieldNames,
            columns, tuples);

    }
 
开发者ID:diennea,项目名称:herddb,代码行数:27,代码来源:CalcitePlanner.java

示例14: buildBeamPipeline

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
@Override public PCollection<BeamRecord> buildBeamPipeline(PCollectionTuple inputPCollections
    , BeamSqlEnv sqlEnv) throws Exception {
  List<BeamRecord> rows = new ArrayList<>(tuples.size());
  String stageName = BeamSqlRelUtils.getStageName(this);
  if (tuples.isEmpty()) {
    throw new IllegalStateException("Values with empty tuples!");
  }

  BeamRecordSqlType beamSQLRowType = CalciteUtils.toBeamRowType(this.getRowType());
  for (ImmutableList<RexLiteral> tuple : tuples) {
    List<Object> fieldsValue = new ArrayList<>(beamSQLRowType.getFieldCount());
    for (int i = 0; i < tuple.size(); i++) {
      fieldsValue.add(BeamTableUtils.autoCastField(
          beamSQLRowType.getFieldTypeByIndex(i), tuple.get(i).getValue()));
    }
    rows.add(new BeamRecord(beamSQLRowType, fieldsValue));
  }

  return inputPCollections.getPipeline().apply(stageName, Create.of(rows))
      .setCoder(beamSQLRowType.getRecordCoder());
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:BeamValuesRel.java

示例15: extractJoinColumns

import org.apache.calcite.rex.RexLiteral; //导入依赖的package包/类
private List<Pair<Integer, Integer>> extractJoinColumns(int leftRowColumnCount) {
  // it's a CROSS JOIN because: condition == true
  if (condition instanceof RexLiteral && (Boolean) ((RexLiteral) condition).getValue()) {
    throw new UnsupportedOperationException("CROSS JOIN is not supported!");
  }

  RexCall call = (RexCall) condition;
  List<Pair<Integer, Integer>> pairs = new ArrayList<>();
  if ("AND".equals(call.getOperator().getName())) {
    List<RexNode> operands = call.getOperands();
    for (RexNode rexNode : operands) {
      Pair<Integer, Integer> pair = extractOneJoinColumn((RexCall) rexNode, leftRowColumnCount);
      pairs.add(pair);
    }
  } else if ("=".equals(call.getOperator().getName())) {
    pairs.add(extractOneJoinColumn(call, leftRowColumnCount));
  } else {
    throw new UnsupportedOperationException(
        "Operator " + call.getOperator().getName() + " is not supported in join condition");
  }

  return pairs;
}
 
开发者ID:apache,项目名称:beam,代码行数:24,代码来源:BeamJoinRel.java


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