ulysses-you commented on code in PR #36856:
URL: https://github.com/apache/spark/pull/36856#discussion_r896333392


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala:
##########
@@ -53,6 +53,17 @@ case class UnaryMinus(
   override def toString: String = s"-$child"
 
   private lazy val numeric = TypeUtils.getNumeric(dataType, failOnError)
+  private lazy val unaryMinusFunc: Any => Any = dataType match {

Review Comment:
   Do you mean rewrite it to ?
   ```scala
   private def unaryMinusFunc: Any => Any = dataType match {
     ......
   ```
   
   The reason I pull out and make it as lazy val is: the data type is known 
before do eval in an expression. Let's say if the data type is integer,
   - then the function can be elimiated to `input  => numeric.negate(input)` 
during execution
   - if you declare it as a function, then the function would be during 
execution:
     ```scala
     dataType match {
       ....
       case _ => input => numeric.negate(input)
     ```
   
   The overhead if not about creating a function, but the data type matching 
elimination. So I think the lazy val is more efficient ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to