本文整理汇总了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));
}
}
示例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");
}
}
示例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());
}
示例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();
}
}
示例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);
}