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

    https://github.com/apache/spark/pull/12373#discussion_r59659273
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/nullExpressions.scala
 ---
    @@ -128,6 +128,58 @@ 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)
    +    dataType match {
    --- End diff --
    
    Thanks, @viirya ! That simplifies the logic!


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to