Github user bomeng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12373#discussion_r59904696
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/nullExpressions.scala
 ---
    @@ -128,6 +128,143 @@ case class IsNaN(child: Expression) extends 
UnaryExpression
     }
     
     /**
    + * An Expression accepts two parameters and returns null if both 
parameters are equal.
    + * If they are not equal, the first parameter value is returned.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(a,b) - Returns null if a equals to b, or a otherwise.")
    +case class NullIf(left: Expression, right: Expression) extends 
BinaryExpression {
    +  override def nullable: Boolean = true
    +  override def dataType: DataType = left.dataType
    +
    +  override def eval(input: InternalRow): Any = {
    +    val valueLeft = left.eval(input)
    +    val valueRight = right.eval(input)
    +    if (valueLeft.equals(valueRight)) {
    +      null
    +    } else {
    +      valueLeft
    +    }
    +  }
    +
    +  override def genCode(ctx: CodegenContext, ev: ExprCode): String = {
    +    val leftGen = left.gen(ctx)
    +    val rightGen = right.gen(ctx)
    +    s"""
    +      ${leftGen.code}
    +      ${rightGen.code}
    +      boolean ${ev.isNull} = false;
    +      ${ctx.javaType(dataType)} ${ev.value} = 
${ctx.defaultValue(dataType)};
    +      if (${ctx.genEqual(dataType, leftGen.value, rightGen.value)}) {
    +        ${ev.isNull} = true;
    +      } else {
    +        ${ev.value} = ${leftGen.value};
    +      }
    +    """
    +  }
    +}
    +
    +/**
    + * An Expression accepts two parameters and returns the second parameter 
if the value
    + * in the first parameter is null; if the first parameter is any value 
other than null,
    + * it is returned unchanged.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(a,b) - Returns b if a is null, or a otherwise.")
    +case class Nvl(left: Expression, right: Expression) extends 
BinaryExpression {
    --- End diff --
    
    I will say, yes, kind of. Here is what I found: 
[difference](http://stackoverflow.com/questions/950084/oracle-differences-between-nvl-and-coalesce)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to