You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/03/30 06:13:41 UTC

[GitHub] [spark] MaxGekk commented on a change in pull request #32001: [SPARK-34902][SQL] Support cast between LongType & DayTimeIntervalType and IntegerType & YearMonthIntervalType

MaxGekk commented on a change in pull request #32001:
URL: https://github.com/apache/spark/pull/32001#discussion_r603803291



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -72,6 +72,11 @@ object Cast {
 
     case (StringType, CalendarIntervalType) => true
 
+    case (LongType, DayTimeIntervalType) => true
+    case (DayTimeIntervalType, LongType) => true
+    case (IntegerType, YearMonthIntervalType) => true
+    case (YearMonthIntervalType, IntegerType) => true

Review comment:
       I think we should support casting from/to any numeric types including Decimal for instance. And handle overflow properly.

##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -1339,6 +1362,19 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit
 
   }
 
+  private[this] def castToDayTimeIntervalCode(from: DataType): CastFunction = from match {
+    case LongType =>
+      (c, evPrim, evNull) =>
+        code"$evPrim = $c;"
+  }
+
+  private[this] def castToYearMonthIntervalCode(from: DataType): CastFunction = from match {
+    case IntegerType =>
+      (c, evPrim, evNull) =>
+        code"$evPrim = $c;"
+

Review comment:
       Please, remove the blank line.

##########
File path: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
##########
@@ -1712,6 +1712,20 @@ class CastSuite extends CastSuiteBase {
       assert(e3.contains("Casting 2147483648 to int causes overflow"))
     }
   }
+
+  test("SPARK-34902: Cast support DayTimeIntervalType and YearMonthIntervalType") {

Review comment:
       @AngersZhuuuu Could you add tests for corner cases like `null`, `Int/Long.MaxValue/MinValue`, `0`, please.
   
   What happens in casting a `Int` to `DayTimeIntervalType`? Will it be automatically converted to `Long`?

##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -1892,6 +1932,11 @@ object AnsiCast {
 
     case (StringType, _: CalendarIntervalType) => true
 
+    case (LongType, DayTimeIntervalType) => true
+    case (DayTimeIntervalType, LongType) => true
+    case (IntegerType, YearMonthIntervalType) => true
+    case (YearMonthIntervalType, IntegerType) => true

Review comment:
       We should allow casting to any numeric type according to the SQL standard. Am I right? @gengliangwang @srielau @cloud-fan




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

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