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

    https://github.com/apache/spark/pull/21367#discussion_r189428463
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
 ---
    @@ -297,13 +279,39 @@ case class Divide(left: Expression, right: 
Expression) extends BinaryArithmetic
               if (${eval1.isNull}) {
                 ${ev.isNull} = true;
               } else {
    -            ${ev.value} = $divide;
    +            ${ev.value} = $operation;
               }
             }""")
         }
       }
     }
     
    +// scalastyle:off line.size.limit
    +@ExpressionDescription(
    +  usage = "expr1 _FUNC_ expr2 - Returns `expr1`/`expr2`. It always 
performs floating point division.",
    +  examples = """
    +    Examples:
    +      > SELECT 3 _FUNC_ 2;
    +       1.5
    +      > SELECT 2L _FUNC_ 2L;
    +       1.0
    +  """)
    +// scalastyle:on line.size.limit
    +case class Divide(left: Expression, right: Expression) extends DivModLike {
    +
    +  override def inputType: AbstractDataType = TypeCollection(DoubleType, 
DecimalType)
    +
    +  override def symbol: String = "/"
    +  override def decimalMethod: String = "$div"
    +  override def nullable: Boolean = true
    +
    +  private lazy val div: (Any, Any) => Any = dataType match {
    +    case ft: FractionalType => 
ft.fractional.asInstanceOf[Fractional[Any]].div
    +  }
    +
    +  override def eval(input: InternalRow): Any = evalHelper(input, div)
    --- End diff --
    
    following my above comment, here we can write
    ```
    private lazy val div = 
dataType.asInstanceOf[FractionType].fractional.asInstanceOf[Fractional[Any]].div
    
    override def evalInternal(input1: Any, input2: Any) = div(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