/** * Converts an expression from {@link SqlNode} to {@link RexNode} format, * mapping identifier references to predefined expressions. * * @param node Expression to translate * @param nameToNodeMap map from String to {@link RexNode}; when an * {@link SqlIdentifier} is encountered, it is used as a * key and translated to the corresponding value from * this map * @return Converted expression */ public RexNode convertExpression( SqlNode node, Map<String, RexNode> nameToNodeMap) { final Map<String, RelDataType> nameToTypeMap = new HashMap<String, RelDataType>(); for (Map.Entry<String, RexNode> entry : nameToNodeMap.entrySet()) { nameToTypeMap.put(entry.getKey(), entry.getValue().getType()); } Blackboard bb = createBlackboard( new ParameterScope((SqlValidatorImpl) validator, nameToTypeMap), nameToNodeMap); return bb.convertExpression(node); }
public void addGroupExpr(SqlNode expr) { RexNode convExpr = bb.convertExpression(expr); final RexNode rex = lookupGroupExpr(expr); if (rex != null) { return; // don't add duplicates, in e.g. "GROUP BY x, y, x" } groupExprs.add(expr); String name = nameMap.get(expr.toString()); addExpr(convExpr, name); final RelDataType type = convExpr.getType(); inputRefs.add(rexBuilder.makeInputRef(type, inputRefs.size())); }
assert convertedExpr != null; if (argTypes != null) { argTypes.add(convertedExpr.getType());
public RelDataType getFieldType(int index) { return exprs.get(index).getType(); } });
public RelDataType get(int index) { return exprs.get(index).getType(); } public int size() {
final int fieldCount = rex.getType().getFieldCount(); RexNode rexNode = rexBuilder.makeFieldAccess(rex, fieldCount - 1); rexNode = rexBuilder.makeCall(SqlStdOperatorTable.IS_TRUE, rexNode);
public RelDataType get(int index) { final int arg = argList.get(index); return arg < inputFields.size() ? inputFields.get(arg).getType() : extraInputs.get(arg - inputFields.size()).getType(); } public int size() {
private boolean isBoolean(RexNode node) { RelDataType type = node.getType(); return SqlTypeUtil.inBooleanFamily(type); }
private RexNode makeCastExactToBoolean(RelDataType toType, RexNode exp) { return makeCall( toType, SqlStdOperatorTable.notEqualsOperator, ImmutableList.<RexNode>of( exp, makeZeroLiteral(exp.getType()))); }
@Override public boolean isAlwaysTrue() { // "c IS NOT NULL" occurs when we expand EXISTS. // This reduction allows us to convert it to a semi-join. switch (getKind()) { case IS_NOT_NULL: return !operands.get(0).getType().isNullable(); default: return false; } }
private RexNode makeCastExactToBoolean(RelDataType toType, RexNode exp) { return makeCall( toType, SqlStdOperatorTable.NOT_EQUALS, ImmutableList.of(exp, makeZeroLiteral(exp.getType()))); }
/** * Retrieves a decimal node's integer representation * * @param decimalNode the decimal value as an opaque type * @return an integer representation of the decimal value */ protected RexNode decodeValue(RexNode decimalNode) { assert SqlTypeUtil.isDecimal(decimalNode.getType()); return builder.decodeIntervalOrDecimal(decimalNode); }
/** * Retrieves a decimal node's integer representation * * @param decimalNode the decimal value as an opaque type * * @return an integer representation of the decimal value */ protected RexNode decodeValue(RexNode decimalNode) { assert (SqlTypeUtil.isDecimal(decimalNode.getType())); return builder.decodeIntervalOrDecimal(decimalNode); }
public Expression implement( RexToLixTranslator translator, RexCall call, NullAs nullAs) { final MethodImplementor implementor = getImplementor( call.getOperands().get(0).getType().getSqlTypeName()); return implementNullSemantics0( translator, call, nullAs, NullPolicy.STRICT, false, implementor); }
public Expression implement( RexToLixTranslator translator, RexCall call, NullAs nullAs) { final MethodImplementor implementor = getImplementor( call.getOperands().get(0).getType().getSqlTypeName()); return implementNullSemantics0( translator, call, nullAs, NullPolicy.STRICT, false, implementor); }
public Expression implement(RexToLixTranslator translator, RexCall call, NullAs nullAs) { // Short-circuit if no cast is required RexNode arg = call.getOperands().get(0); if (call.getType().equals(arg.getType())) { // No cast required, omit cast return translator.translate(arg, nullAs); } return accurate.implement(translator, call, nullAs); } }
private RexNode convertPlus(SqlRexContext cx, SqlCall call) { final RexNode rex = convertCall(cx, call); switch (rex.getType().getSqlTypeName()) { case DATE: case TIME: case TIMESTAMP: return convertCall(cx, call, SqlStdOperatorTable.DATETIME_PLUS); default: return rex; } }
/** * Creates a key for {@link RexNode} which is the same as another key of * another RexNode only if the two have both the same type and textual * representation. For example, "10" integer and "10" bigint result in * different keys. */ public static Pair<String, String> makeKey(RexNode expr) { return Pair.of(expr.toString(), expr.getType().getFullTypeString()); }