Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21367#discussion_r189428530
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
 ---
    @@ -313,81 +321,26 @@ case class Divide(left: Expression, right: 
Expression) extends BinaryArithmetic
           > SELECT MOD(2, 1.8);
            0.2
       """)
    -case class Remainder(left: Expression, right: Expression) extends 
BinaryArithmetic {
    +case class Remainder(left: Expression, right: Expression) extends 
DivModLike {
     
       override def inputType: AbstractDataType = NumericType
     
       override def symbol: String = "%"
       override def decimalMethod: String = "remainder"
    -  override def nullable: Boolean = true
     
       private lazy val integral = dataType match {
         case i: IntegralType => i.integral.asInstanceOf[Integral[Any]]
         case i: FractionalType => i.asIntegral.asInstanceOf[Integral[Any]]
       }
     
       override def eval(input: InternalRow): Any = {
    -    val input2 = right.eval(input)
    -    if (input2 == null || input2 == 0) {
    -      null
    -    } else {
    -      val input1 = left.eval(input)
    -      if (input1 == null) {
    -        null
    -      } else {
    -        input1 match {
    -          case d: Double => d % input2.asInstanceOf[java.lang.Double]
    -          case f: Float => f % input2.asInstanceOf[java.lang.Float]
    -          case _ => integral.rem(input1, input2)
    -        }
    +    evalHelper(input, (input1, input2) => {
    --- End diff --
    
    and here can be
    ```
    private lazy val mod: (Any, Any) => Any = dataType match {
      case i: IntegralType =>
        val integral = i.integral.asInstanceOf[Integral[Any]]
        (input1, input2) => integral.rem(input1, input2)
    
      case FloatType =>
        (input1, input2) => input1.asInstanceOf[java.lang.Float] % 
input2..asInstanceOf[java.lang.Float]
    
      case DoubleType =>
          (input1, input2) => input1.asInstanceOf[java.lang.Double] % 
input2..asInstanceOf[java.lang.Double]
    }
    
    override def evalInternal(input1: Any, input2: Any) = mod(input1, input2)
    ```


---

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

Reply via email to