private void addResult(RexNode exp) {
      // Cast of literal can't be reduced, so skip those (otherwise we'd
      // go into an infinite loop as we add them back).
      if (exp.getKind() == RexKind.Cast) {
        RexCall cast = (RexCall) exp;
        RexNode operand = cast.getOperands()[0];
        if (operand instanceof RexLiteral) {
          return;
        }
      }
      constExprs.add(exp);

      // In the case where the expression corresponds to a UDR argument,
      // we need to preserve casts.  Note that this only applies to
      // the topmost argument, not expressions nested within the UDR
      // call.
      //
      // REVIEW zfong 6/13/08 - Are there other expressions where we
      // also need to preserve casts?
      if (parentCallTypeStack.isEmpty()) {
        addCasts.add(false);
      } else {
        addCasts.add(
            parentCallTypeStack.get(parentCallTypeStack.size() - 1)
                instanceof FarragoUserDefinedRoutine);
      }
    }
Example #2
0
 /**
  * Returns whether a node represents the NULL value or a series of nested CAST(NULL as <TYPE>)
  * calls<br>
  * For Example:<br>
  * isNull(CAST(CAST(NULL as INTEGER) AS VARCHAR(1))) returns true
  */
 public static boolean isNull(RexNode node) {
   /* Checks to see if the RexNode is null */
   return RexLiteral.isNullLiteral(node)
       || ((node.getKind() == RexKind.Cast) && isNull(((RexCall) node).operands[0]));
 }