You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "wangyum (via GitHub)" <gi...@apache.org> on 2023/09/04 14:56:51 UTC

[GitHub] [spark] wangyum commented on a diff in pull request #42804: [SPARK-45071][SQL] Optimize the processing speed of `BinaryArithmetic#dataType` when processing multi-column data

wangyum commented on code in PR #42804:
URL: https://github.com/apache/spark/pull/42804#discussion_r1315032583


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala:
##########
@@ -234,10 +234,17 @@ abstract class BinaryArithmetic extends BinaryOperator
     case _ => super.checkInputDataTypes()
   }
 
-  override def dataType: DataType = (left.dataType, right.dataType) match {
-    case (DecimalType.Fixed(p1, s1), DecimalType.Fixed(p2, s2)) =>
-      resultDecimalType(p1, s1, p2, s2)
-    case _ => left.dataType
+  override def dataType: DataType = (left, right) match {
+    case (_, r: AttributeReference) if !r.dataType.isInstanceOf[DecimalType] =>
+      left.dataType
+    case (l: AttributeReference, _) if !l.dataType.isInstanceOf[DecimalType] =>
+      left.dataType
+    case (_, _) =>
+      (left.dataType, right.dataType) match {
+        case (DecimalType.Fixed(p1, s1), DecimalType.Fixed(p2, s2)) =>
+          resultDecimalType(p1, s1, p2, s2)
+        case _ => left.dataType
+      }

Review Comment:
   Can we change it to lazy val? For example:
   ```scala
     private lazy val internalDataType: DataType = (left.dataType, right.dataType) match {
       case (DecimalType.Fixed(p1, s1), DecimalType.Fixed(p2, s2)) =>
         resultDecimalType(p1, s1, p2, s2)
       case _ => left.dataType
     }
   
     override def dataType: DataType = internalDataType
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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