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


Java RexBuilder.makeExactLiteral方法代码示例

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


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

示例1: singleton

import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>{@code COUNT(*)}, and {@code COUNT} applied to all NOT NULL arguments,
 * become {@code 1}; otherwise
 * {@code CASE WHEN arg0 IS NOT NULL THEN 1 ELSE 0 END}.
 */
public RexNode singleton(RexBuilder rexBuilder, RelDataType inputRowType,
    AggregateCall aggregateCall) {
  final List<RexNode> predicates = new ArrayList<>();
  for (Integer arg : aggregateCall.getArgList()) {
    final RelDataType type = inputRowType.getFieldList().get(arg).getType();
    if (type.isNullable()) {
      predicates.add(
          rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL,
              rexBuilder.makeInputRef(type, arg)));
    }
  }
  final RexNode predicate =
      RexUtil.composeConjunction(rexBuilder, predicates, true);
  if (predicate == null) {
    return rexBuilder.makeExactLiteral(BigDecimal.ONE);
  } else {
    return rexBuilder.makeCall(SqlStdOperatorTable.CASE, predicate,
        rexBuilder.makeExactLiteral(BigDecimal.ONE),
        rexBuilder.makeExactLiteral(BigDecimal.ZERO));
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:SqlSplittableAggFunction.java

示例2: literal

import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
/** Creates a literal (constant expression). */
public RexNode literal(Object value) {
  final RexBuilder rexBuilder = cluster.getRexBuilder();
  if (value == null) {
    return rexBuilder.constantNull();
  } else if (value instanceof Boolean) {
    return rexBuilder.makeLiteral((Boolean) value);
  } else if (value instanceof BigDecimal) {
    return rexBuilder.makeExactLiteral((BigDecimal) value);
  } else if (value instanceof Float || value instanceof Double) {
    return rexBuilder.makeApproxLiteral(
        BigDecimal.valueOf(((Number) value).doubleValue()));
  } else if (value instanceof Number) {
    return rexBuilder.makeExactLiteral(
        BigDecimal.valueOf(((Number) value).longValue()));
  } else if (value instanceof String) {
    return rexBuilder.makeLiteral((String) value);
  } else {
    throw new IllegalArgumentException("cannot convert " + value
        + " (" + value.getClass() + ") to a constant");
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:RelBuilder.java

示例3: addRow

import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
private void addRow(ImmutableList.Builder<ImmutableList<RexLiteral>> builder,
    RexBuilder rexBuilder, Object... values) {
  ImmutableList.Builder<RexLiteral> b = ImmutableList.builder();
  final RelDataType varcharType =
      rexBuilder.getTypeFactory().createSqlType(SqlTypeName.VARCHAR);
  for (Object value : values) {
    final RexLiteral literal;
    if (value == null) {
      literal = rexBuilder.makeNullLiteral(varcharType);
    } else if (value instanceof Integer) {
      literal = rexBuilder.makeExactLiteral(
          BigDecimal.valueOf((Integer) value));
    } else {
      literal = rexBuilder.makeLiteral((String) value);
    }
    b.add(literal);
  }
  builder.add(b.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:RelMetadataTest.java

示例4: newColumnDefaultValue

import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
@Override public RexNode newColumnDefaultValue(RelOptTable table,
    int iColumn, InitializerContext context) {
  final RexBuilder rexBuilder = context.getRexBuilder();
  final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
  switch (iColumn) {
  case 0:
    return rexBuilder.makeExactLiteral(new BigDecimal(123),
        typeFactory.createSqlType(SqlTypeName.INTEGER));
  case 1:
    return rexBuilder.makeLiteral("Bob");
  case 5:
    return rexBuilder.makeExactLiteral(new BigDecimal(555),
        typeFactory.createSqlType(SqlTypeName.INTEGER));
  default:
    return rexBuilder.constantNull();
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:MockCatalogReader.java

示例5: convertFloorCeil

import org.apache.calcite.rex.RexBuilder; //导入方法依赖的package包/类
protected RexNode convertFloorCeil(SqlRexContext cx, SqlCall call) {
  final boolean floor = call.getKind() == SqlKind.FLOOR;
  // Rewrite floor, ceil of interval
  if (call.operandCount() == 1
      && call.operand(0) instanceof SqlIntervalLiteral) {
    final SqlIntervalLiteral literal = call.operand(0);
    SqlIntervalLiteral.IntervalValue interval =
        (SqlIntervalLiteral.IntervalValue) literal.getValue();
    BigDecimal val =
        interval.getIntervalQualifier().getStartUnit().multiplier;
    RexNode rexInterval = cx.convertExpression(literal);

    final RexBuilder rexBuilder = cx.getRexBuilder();
    RexNode zero = rexBuilder.makeExactLiteral(BigDecimal.valueOf(0));
    RexNode cond = ge(rexBuilder, rexInterval, zero);

    RexNode pad =
        rexBuilder.makeExactLiteral(val.subtract(BigDecimal.ONE));
    RexNode cast = rexBuilder.makeReinterpretCast(
        rexInterval.getType(), pad, rexBuilder.makeLiteral(false));
    RexNode sum = floor
        ? minus(rexBuilder, rexInterval, cast)
        : plus(rexBuilder, rexInterval, cast);

    RexNode kase = floor
        ? case_(rexBuilder, rexInterval, cond, sum)
        : case_(rexBuilder, sum, cond, rexInterval);

    RexNode factor = rexBuilder.makeExactLiteral(val);
    RexNode div = divideInt(rexBuilder, kase, factor);
    return multiply(rexBuilder, div, factor);
  }

  // normal floor, ceil function
  return convertFunction(cx, (SqlFunction) call.getOperator(), call);
}
 
开发者ID:apache,项目名称:calcite,代码行数:37,代码来源:StandardConvertletTable.java


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