gengliangwang commented on a change in pull request #33775:
URL: https://github.com/apache/spark/pull/33775#discussion_r690938927



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
##########
@@ -178,6 +178,11 @@ object AnsiTypeCoercion extends TypeCoercionBase {
       case (StringType, DecimalType) if isInputFoldable =>
         Some(DecimalType.SYSTEM_DEFAULT)
 
+      // If the target type is Decimal type with precision greater than 11 and 
scale is 6,
+      // cast the input to decimal.
+      case (_: IntegerType, t: DecimalType) if (t.precision > 11 && t.scale == 
6) =>

Review comment:
       ```suggestion
         case (n: NumericType, t: DecimalType) if t.isWiderThan(n) =>
   ```

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
##########
@@ -178,6 +178,11 @@ object AnsiTypeCoercion extends TypeCoercionBase {
       case (StringType, DecimalType) if isInputFoldable =>
         Some(DecimalType.SYSTEM_DEFAULT)
 
+      // If the target type is Decimal type with precision greater than 11 and 
scale is 6,
+      // cast the input to decimal.
+      case (_: IntegerType, t: DecimalType) if (t.precision > 11 && t.scale == 
6) =>

Review comment:
       Let's make it more general here.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
##########
@@ -178,6 +178,11 @@ object AnsiTypeCoercion extends TypeCoercionBase {
       case (StringType, DecimalType) if isInputFoldable =>
         Some(DecimalType.SYSTEM_DEFAULT)
 
+      // If the target type is Decimal type with precision greater than 11 and 
scale is 6,

Review comment:
       Please update the corresponding comment if the suggestion change is 
accepted.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
##########
@@ -2559,20 +2559,13 @@ case class MakeTimestamp(
   // Accept `sec` as DecimalType to avoid loosing precision of microseconds 
while converting
   // them to the fractional part of `sec`.
   override def inputTypes: Seq[AbstractDataType] =
-    Seq(IntegerType, IntegerType, IntegerType, IntegerType, IntegerType,
-      TypeCollection(DecimalType(8, 6), IntegerType, NullType)) ++ 
timezone.map(_ => StringType)
+    Seq(IntegerType, IntegerType, IntegerType, IntegerType, IntegerType, 
DecimalType(16, 6)) ++

Review comment:
       Add comment for why choosing `DecimalType(16, 6))`

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
##########
@@ -178,6 +178,10 @@ object AnsiTypeCoercion extends TypeCoercionBase {
       case (StringType, DecimalType) if isInputFoldable =>
         Some(DecimalType.SYSTEM_DEFAULT)
 
+      // If the target type is Decimal type and it wider than input, cast the 
input to decimal.

Review comment:
       On second thought. This code should not be needed.
   It will be covered by line 189
   ```
   case (n1: NumericType, n2: NumericType) =>
           val widerType = findWiderTypeForTwo(n1, n2)
            ....
   ```
   
   We don't need to touch `AnsiTypeCoercion.scala`




-- 
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