@Override public Double visitLiteral(RexLiteral literal) { if (literal.isAlwaysFalse() || RexUtil.isNull(literal)) { return 0.0; } else if (literal.isAlwaysTrue()) { return 1.0; } else { assert false; } return null; } }
@Override public RexNode visitLiteral(RexLiteral literal) { // Use nullIndicator to decide whether to project null. // Do nothing if the literal is null. if (!RexUtil.isNull(literal) && projectPulledAboveLeftCorrelator && (nullIndicator != null)) { return createCaseExpression( nullIndicator, rexBuilder.constantNull(), literal); } return literal; }
@Override public RexNode visitLiteral(RexLiteral literal) { // Use nullIndicator to decide whether to project null. // Do nothing if the literal is null. if (!RexUtil.isNull(literal) && projectPulledAboveLeftCorrelator && (nullIndicator != null)) { return createCaseExpression( nullIndicator, rexBuilder.constantNull(), literal); } return literal; }
/** * Interprets argument as a constraint; if not possible returns null. */ public static Constraint of(RexNode n) { if (!(n instanceof RexCall)) { return null; } RexCall call = (RexCall) n; if (call.getOperator().getKind() != SqlKind.EQUALS) { return null; } RexNode opA = call.operands.get(0); RexNode opB = call.operands.get(1); if (RexUtil.isNull(opA) || RexUtil.isNull(opB)) { // dont try to compare nulls return null; } if (isConstExpr(opA) && isColumnExpr(opB)) { return new Constraint(opB, opA); } if (isColumnExpr(opA) && isConstExpr(opB)) { return new Constraint(opA, opB); } return null; }
@Override public ASTNode visitLiteral(RexLiteral literal) { if (RexUtil.isNull(literal) && literal.getType().getSqlTypeName() != SqlTypeName.NULL && rexBuilder != null) { // It is NULL value with different type, we need to introduce a CAST // to keep it if(nullLiteralMap.containsKey(literal)) { return ASTBuilder.literal(literal, useTypeQualInLiteral); } nullLiteralMap.put(literal, true); RexNode r = rexBuilder.makeAbstractCast(literal.getType(), literal); return r.accept(this); } return ASTBuilder.literal(literal, useTypeQualInLiteral); }
/** * 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; } }
@Override public RexNode visitLiteral(RexLiteral literal) { // Use nullIndicator to decide whether to project null. // Do nothing if the literal is null. if (!RexUtil.isNull(literal) && projectPulledAboveLeftCorrelator && (nullIndicator != null)) { return createCaseExpression( nullIndicator, rexBuilder.constantNull(), literal); } return literal; }
/** * 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; } }
@Override public RexNode visitLiteral(RexLiteral literal) { // Use nullIndicator to decide whether to project null. // Do nothing if the literal is null. if (!RexUtil.isNull(literal) && projectPulledAboveLeftCorrelator && (nullIndicator != null)) { return createCaseExpression( nullIndicator, rexBuilder.constantNull(), literal); } return literal; }
@Override public RexNode visitLiteral(RexLiteral literal) { // Use nullIndicator to decide whether to project null. // Do nothing if the literal is null. if (!RexUtil.isNull(literal) && projectPulledAboveLeftCorrelator && (nullIndicator != null)) { return createCaseExpression( nullIndicator, rexBuilder.constantNull(), literal); } return literal; }
private RexNode simplifyCoalesce(RexCall call) { final Set<RexNode> operandSet = new HashSet<>(); final List<RexNode> operands = new ArrayList<>(); for (RexNode operand : call.getOperands()) { operand = simplify(operand, UNKNOWN); if (!RexUtil.isNull(operand) && operandSet.add(operand)) { operands.add(operand); } if (!operand.getType().isNullable()) { break; } } switch (operands.size()) { case 0: return rexBuilder.makeNullLiteral(call.type); case 1: return operands.get(0); default: if (operands.equals(call.operands)) { return call; } return call.clone(call.type, operands); } }
private RexNode simplifyIsNull(RexNode a) { if (!a.getType().isNullable()) { return rexBuilder.makeLiteral(false); } if (RexUtil.isNull(a)) { return rexBuilder.makeLiteral(true); } switch (Strong.policy(a.getKind())) { case NOT_NULL: return rexBuilder.makeLiteral(false); case ANY: // "f" is a strong operator, so "f(operand0, operand1) IS NULL" simplifies // to "operand0 IS NULL OR operand1 IS NULL" final List<RexNode> operands = new ArrayList<>(); for (RexNode operand : ((RexCall) a).getOperands()) { final RexNode simplified = simplifyIsNull(operand); if (simplified == null) { operands.add( rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, operand)); } else { operands.add(simplified); } } return RexUtil.composeDisjunction(rexBuilder, operands, false); case AS_IS: default: return null; } }
private RexNode simplifyIsNull(RexNode a) { if (!a.getType().isNullable()) { return rexBuilder.makeLiteral(false); } if (RexUtil.isNull(a)) { return rexBuilder.makeLiteral(true); } switch (Strong.policy(a.getKind())) { case NOT_NULL: return rexBuilder.makeLiteral(false); case ANY: // "f" is a strong operator, so "f(operand0, operand1) IS NULL" simplifies // to "operand0 IS NULL OR operand1 IS NULL" final List<RexNode> operands = new ArrayList<>(); for (RexNode operand : ((RexCall) a).getOperands()) { final RexNode simplified = simplifyIsNull(operand); if (simplified == null) { operands.add( rexBuilder.makeCall(SqlStdOperatorTable.IS_NULL, operand)); } else { operands.add(simplified); } } return RexUtil.composeDisjunction(rexBuilder, operands, false); case AS_IS: default: return null; } }
if (unknownAs == FALSE && RexUtil.isNull(operands.get(i))) { values.add(rexBuilder.makeLiteral(false).toString()); } else { } else if (operand.isAlwaysFalse() || RexUtil.isNull(operand)) { if (unknownAs == FALSE && RexUtil.isNull(operand)) { values.add(rexBuilder.makeLiteral(false).toString()); } else { && !RexUtil.isNull(pair.getValue())) { break; && (unknownAs == UNKNOWN || !RexUtil.isNull(pair.e.getValue()))) { break trueFalse;
if (!RexUtil.isNull(opt)) { assertEquals(nodeToString(node) + " is always null, so it should simplify to NULL " + uaf,
if (!RexUtil.isNull(opt)) { assertEquals(nodeToString(node) + " is always null, so it should simplify to NULL " + uaf,