cloud-fan commented on a change in pull request #32266:
URL: https://github.com/apache/spark/pull/32266#discussion_r620960081
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
##########
@@ -1774,6 +1774,45 @@ class CastSuite extends CastSuiteBase {
assert(e3.contains("Casting 2147483648 to int causes overflow"))
}
}
+
+ test("SPARK-35111: Cast string to year-month interval") {
+ checkEvaluation(cast(Literal.create("INTERVAL '0-0' YEAR TO MONTH"),
+ YearMonthIntervalType), 0)
+ checkEvaluation(cast(Literal.create("0-0"), YearMonthIntervalType), 0)
+ checkEvaluation(cast(Literal.create("INTERVAL '-1-0' YEAR TO MONTH"),
+ YearMonthIntervalType), -12)
+ checkEvaluation(cast(Literal.create("-1-0"), YearMonthIntervalType), -12)
+ checkEvaluation(cast(Literal.create("INTERVAL '10-1' YEAR TO MONTH"),
+ YearMonthIntervalType), 121)
+ checkEvaluation(cast(Literal.create("10-1"), YearMonthIntervalType), 121)
+ checkEvaluation(cast(Literal.create("interval '10-1' year TO MONTH"),
+ YearMonthIntervalType), 121)
+ checkEvaluation(cast(Literal.create(null, StringType),
YearMonthIntervalType), null)
+
+ Seq("INTERVAL '0-0' YEAR TO MONTH" -> "INTERVAL '0-0' YEAR TO MONTH",
+ "INTERVAL '10-1' YEAR TO MONTH" -> "INTERVAL '10-1' YEAR TO MONTH",
+ "INTERVAL '-178956970-7' YEAR TO MONTH" -> "INTERVAL '-178956970-7' YEAR
TO MONTH",
+ "INTERVAL '178956970-7' YEAR TO MONTH" -> "INTERVAL '178956970-7' YEAR
TO MONTH",
+ "INTERVAL '-178956970-8' YEAR TO MONTH" -> "INTERVAL '-178956970-8' YEAR
TO MONTH"
Review comment:
they key and value are always the same?
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
##########
@@ -1774,6 +1774,45 @@ class CastSuite extends CastSuiteBase {
assert(e3.contains("Casting 2147483648 to int causes overflow"))
}
}
+
+ test("SPARK-35111: Cast string to year-month interval") {
+ checkEvaluation(cast(Literal.create("INTERVAL '0-0' YEAR TO MONTH"),
+ YearMonthIntervalType), 0)
+ checkEvaluation(cast(Literal.create("0-0"), YearMonthIntervalType), 0)
+ checkEvaluation(cast(Literal.create("INTERVAL '-1-0' YEAR TO MONTH"),
+ YearMonthIntervalType), -12)
+ checkEvaluation(cast(Literal.create("-1-0"), YearMonthIntervalType), -12)
+ checkEvaluation(cast(Literal.create("INTERVAL '10-1' YEAR TO MONTH"),
+ YearMonthIntervalType), 121)
+ checkEvaluation(cast(Literal.create("10-1"), YearMonthIntervalType), 121)
+ checkEvaluation(cast(Literal.create("interval '10-1' year TO MONTH"),
+ YearMonthIntervalType), 121)
+ checkEvaluation(cast(Literal.create(null, StringType),
YearMonthIntervalType), null)
+
+ Seq("INTERVAL '0-0' YEAR TO MONTH" -> "INTERVAL '0-0' YEAR TO MONTH",
+ "INTERVAL '10-1' YEAR TO MONTH" -> "INTERVAL '10-1' YEAR TO MONTH",
+ "INTERVAL '-178956970-7' YEAR TO MONTH" -> "INTERVAL '-178956970-7' YEAR
TO MONTH",
+ "INTERVAL '178956970-7' YEAR TO MONTH" -> "INTERVAL '178956970-7' YEAR
TO MONTH",
+ "INTERVAL '-178956970-8' YEAR TO MONTH" -> "INTERVAL '-178956970-8' YEAR
TO MONTH"
Review comment:
the key and value are always the same?
--
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]