public boolean isAlwaysTrue() { if (typeName != SqlTypeName.BOOLEAN) { return false; } return booleanValue(this); }
/** * Returns the value of this literal, in the form that the rex-to-lix * translator wants it. */ public Object getValue3() { switch (typeName) { case DECIMAL: assert value instanceof BigDecimal; return value; default: return getValue2(); } }
public RexNode visitLiteral(RexLiteral literal) { return new RexLiteral( literal.getValue(), builder.getTypeFactory().copyType(literal.getType()), literal.getTypeName()); }
assert literalExpr.isA(SqlKind.CAST); RexNode child = ((RexCall) literalExpr).getOperands().get(0); assert RexLiteral.isNullLiteral(child); Comparable value = literal.getValue();
if (literal.getTypeName() == SqlTypeName.SYMBOL) { final SqlLiteral.SqlSymbol symbol = (SqlLiteral.SqlSymbol) literal.getValue(); return SqlLiteral.createSymbol(symbol, POS); switch (literal.getTypeName().getFamily()) { case CHARACTER: return SqlLiteral.createCharString((String) literal.getValue2(), POS); case NUMERIC: case EXACT_NUMERIC: return SqlLiteral.createExactNumeric(literal.getValue().toString(), POS); case APPROXIMATE_NUMERIC: return SqlLiteral.createApproxNumeric( literal.getValue().toString(), POS); case BOOLEAN: return SqlLiteral.createBoolean((Boolean) literal.getValue(), POS); case DATE: return SqlLiteral.createDate((Calendar) literal.getValue(), POS); case TIME: return SqlLiteral.createTime((Calendar) literal.getValue(), literal.getType().getPrecision(), POS); case TIMESTAMP: return SqlLiteral.createTimestamp((Calendar) literal.getValue(), literal.getType().getPrecision(), POS); case ANY: switch (literal.getTypeName()) { case NULL: return SqlLiteral.createNull(POS);
/** * Sets a finite value for this endpoint. * * @param boundType bound type (upper/lower) * @param strictness boundary strictness * @param coordinate endpoint position */ void setFinite( SargBoundType boundType, SargStrictness strictness, RexNode coordinate) { // validate the input assert (coordinate != null); if (!(coordinate instanceof RexDynamicParam) && !(coordinate instanceof RexInputRef)) { assert (coordinate instanceof RexLiteral); RexLiteral literal = (RexLiteral) coordinate; if (!RexLiteral.isNullLiteral(literal)) { assert (SqlTypeUtil.canAssignFrom( dataType, literal.getType())); } } this.boundType = boundType; this.coordinate = coordinate; this.strictness = strictness; convertToTargetType(); }
if (exp instanceof RexLiteral) { RexLiteral literal = (RexLiteral) exp; Comparable value = literal.getValue(); if (RexLiteral.valueMatchesType(value, sqlType, false) && (!(value instanceof NlsString) || (type.getPrecision() || (type.getPrecision() >= ((ByteString) value).length()))) { switch (literal.getTypeName()) { case CHAR: if (value instanceof NlsString) { BigDecimal value2 = (BigDecimal) value; final long multiplier = literal.getType().getIntervalQualifier().getStartUnit() .multiplier; SqlTypeName typeName = type.getSqlTypeName(); type, typeName); return makeLiteral(value, type, literal.getTypeName());
private RexNode castNullLiteralIfNeeded(RexNode node, RelDataType type) { if (!RexLiteral.isNullLiteral(node)) { return node; } return rexBuilder.makeCast(type, node); }
} else if (rex instanceof RexLiteral) { final RexLiteral literal = (RexLiteral) rex; switch (literal.getTypeName().getFamily()) { case CHARACTER: return SqlLiteral.createCharString((String) literal.getValue2(), POS); case NUMERIC: case EXACT_NUMERIC: return SqlLiteral.createExactNumeric(literal.getValue().toString(), POS); case APPROXIMATE_NUMERIC: return SqlLiteral.createApproxNumeric( literal.getValue().toString(), POS); case BOOLEAN: return SqlLiteral.createBoolean((Boolean) literal.getValue(), POS); case ANY: switch (literal.getTypeName()) { case NULL: return SqlLiteral.createNull(POS);
if (node instanceof RexLiteral) { RexLiteral literal = (RexLiteral) node; if (literal.getTypeName() == SqlTypeName.NULL) { assert null == literal.getValue(); return true; } else {
private static String parseFieldAccess(RexNode rex) { if (rex instanceof RexCall) { final RexCall call = (RexCall) rex; if (call.getOperator() == SqlStdOperatorTable.itemOp && call.getOperands().size() == 2 && call.getOperands().get(0) instanceof RexInputRef && ((RexInputRef) call.getOperands().get(0)).getIndex() == 0 && call.getOperands().get(1) instanceof RexLiteral) { RexLiteral arg = (RexLiteral) call.getOperands().get(1); if (arg.getTypeName() == SqlTypeName.CHAR) { return (String) arg.getValue2(); } } } return null; }
if (exp instanceof RexLiteral) { RexLiteral literal = (RexLiteral) exp; Comparable value = literal.getValue(); if (RexLiteral.valueMatchesType(value, sqlType, false) && (!(value instanceof NlsString) || (type.getPrecision() >= ((NlsString) value).getValue().length()))) switch (literal.getTypeName()) { case CHAR: if (value instanceof NlsString) { break; return makeLiteral(value, type, literal.getTypeName());
@Override public RexNode visitLiteral(RexLiteral literal) { RexInputRef ref = constantPool.get(literal); if (ref != null) { return ref; } constants.add(literal); ref = new RexInputRef(constantPool.size() + inputFieldCount, literal.getType()); constantPool.put(literal, ref); return ref; } };
/** * Returns the selectivity value stored in the rexnode * * @param artificialSelecFuncNode rexnode containing the selectivity value * @return selectivity value */ public static double getSelectivityValue(RexNode artificialSelecFuncNode) { assert artificialSelecFuncNode instanceof RexCall; RexCall call = (RexCall) artificialSelecFuncNode; assert call.getOperator() == ARTIFICIAL_SELECTIVITY_FUNC; RexNode operand = call.getOperands().get(0); BigDecimal bd = (BigDecimal) ((RexLiteral) operand).getValue(); return bd.doubleValue(); }
charset.name(), collation); return new RexLiteral(str, type, typeName); case BOOLEAN: boolean b = ConversionUtil.toBoolean(literal); return new RexLiteral(b, type, typeName); case DECIMAL: case DOUBLE: BigDecimal d = new BigDecimal(literal); return new RexLiteral(d, type, typeName); case BINARY: byte [] bytes = ConversionUtil.toByteArrayFromString(literal, 16); ByteBuffer buffer = ByteBuffer.wrap(bytes); return new RexLiteral(buffer, type, typeName); case NULL: return new RexLiteral(null, type, typeName); case INTERVAL_DAY_TIME: long millis = literal, type.getIntervalQualifier()); return new RexLiteral(BigDecimal.valueOf(millis), type, typeName); case INTERVAL_YEAR_MONTH: long months = literal, type.getIntervalQualifier()); return new RexLiteral(BigDecimal.valueOf(months), type, typeName); case DATE:
public static int intValue(RexNode node) { final Comparable value = findValue(node); return ((Number) value).intValue(); }
public RexLiteral clone() { return new RexLiteral(value, type, typeName); }