/** * 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(); } }
/** * 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 static List<Object> asValues2( List<RexLiteral> literals ) { List<Object> values = new ArrayList<Object>(); for( RexLiteral literal : literals ) values.add( literal.getValue2() ); return values; }
/** * Returns whether a node represents the NULL value or a series of nested * {@code CAST(NULL AS type)} calls. For example: * <code>isNull(CAST(CAST(NULL as INTEGER) AS VARCHAR(1)))</code> * returns {@code true}. */ public static boolean isNull(RexNode expr) { switch (expr.getKind()) { case LITERAL: return ((RexLiteral) expr).getValue2() == null; case CAST: return isNull(((RexCall) expr).operands.get(0)); default: return false; } }
/** * Returns whether an expression always evaluates to null. * * <p>Like {@link RexUtil#isNull(RexNode)}, null literals are null, and | * casts of null literals are null. But this method also regards references * to null expressions as null.</p> * * @param expr Expression * @return Whether expression always evaluates to null */ public boolean isNull(RexNode expr) { switch (expr.getKind()) { case LITERAL: return ((RexLiteral) expr).getValue2() == null; case LOCAL_REF: RexLocalRef inputRef = (RexLocalRef) expr; return isNull(exprs.get(inputRef.index)); case CAST: return isNull(((RexCall) expr).operands.get(0)); default: return false; } }
@Override public Void visitCall(RexCall call) { if (call.getOperator() == RexBuilder.GET_OPERATOR) { RexLiteral literal = (RexLiteral) call.getOperands().get(1); extraFields.add( new RelDataTypeFieldImpl( (String) literal.getValue2(), -1, call.getType())); } return super.visitCall(call); } }
@Override public Void visitCall(RexCall call) { if (call.getOperator() == RexBuilder.GET_OPERATOR) { RexLiteral literal = (RexLiteral) call.getOperands().get(1); extraFields.add( new RelDataTypeFieldImpl( (String) literal.getValue2(), -1, call.getType())); } return super.visitCall(call); } }
@Override public RexNode visitCall(RexCall call) { if (call.getOperator() == RexBuilder.GET_OPERATOR) { final String name = (String) ((RexLiteral) call.getOperands().get(1)).getValue2(); final int i = lookup(fields, name); if (i >= 0) { return RexInputRef.of(i, fields); } } return super.visitCall(call); }
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; }
@Override public RexNode visitCall(RexCall call) { if (call.getOperator() == RexBuilder.GET_OPERATOR) { final String name = (String) ((RexLiteral) call.getOperands().get(1)).getValue2(); final int i = lookup(fields, name); if (i >= 0) { return RexInputRef.of(i, fields); } } return super.visitCall(call); }
value = rexLiteral.getValue2(); break;
public void check(RexBuilder rexBuilder, RexExecutorImpl executor) { final List<RexNode> reducedValues = new ArrayList<RexNode>(); final RexLiteral hello = rexBuilder.makeCharLiteral( new NlsString("Hello world!", null, null)); final RexNode plus = rexBuilder.makeCall(SqlStdOperatorTable.PLUS, rexBuilder.makeExactLiteral(BigDecimal.ONE), rexBuilder.makeExactLiteral(BigDecimal.ONE)); RexLiteral four = rexBuilder.makeExactLiteral(BigDecimal.valueOf(4)); final RexNode substring = rexBuilder.makeCall(SqlStdOperatorTable.SUBSTRING, hello, plus, four); executor.reduce(rexBuilder, ImmutableList.of(substring, plus), reducedValues); assertThat(reducedValues.size(), equalTo(2)); assertThat(reducedValues.get(0), instanceOf(RexLiteral.class)); assertThat(((RexLiteral) reducedValues.get(0)).getValue2(), equalTo((Object) "ello")); // substring('Hello world!, 2, 4) assertThat(reducedValues.get(1), instanceOf(RexLiteral.class)); assertThat(((RexLiteral) reducedValues.get(1)).getValue2(), equalTo((Object) 2L)); } });
switch (literal.getTypeName().getFamily()) { case CHARACTER: return SqlLiteral.createCharString((String) literal.getValue2(), POS); case NUMERIC: case EXACT_NUMERIC:
case LITERAL: final RexLiteral literal = (RexLiteral) node; final Object value2 = literal.getValue2(); if (value2 == null) {
return SqlLiteral.createCharString((String) literal.getValue2(), POS); case NUMERIC: case EXACT_NUMERIC: