/** * Returns whether a node represents the NULL value. * * <p>Examples: * * <ul> * <li>For {@link org.eigenbase.rex.RexLiteral} Unknown, returns false. * <li>For <code>CAST(NULL AS <i>type</i>)</code>, returns true if <code> * allowCast</code> is true, false otherwise. * <li>For <code>CAST(CAST(NULL AS <i>type</i>) AS <i>type</i>))</code>, returns false. * </ul> */ public static boolean isNullLiteral(RexNode node, boolean allowCast) { if (node instanceof RexLiteral) { RexLiteral literal = (RexLiteral) node; if (literal.getTypeName() == SqlTypeName.NULL) { assert (null == literal.getValue()); return true; } else { // We don't regard UNKNOWN -- SqlLiteral(null,Boolean) -- as // NULL. return false; } } if (allowCast) { if (node.isA(RexKind.Cast)) { RexCall call = (RexCall) node; if (isNullLiteral(call.operands[0], false)) { // node is "CAST(NULL as type)" return true; } } } return false; }