cloud-fan commented on a change in pull request #34494:
URL: https://github.com/apache/spark/pull/34494#discussion_r749070604
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
##########
@@ -580,4 +584,329 @@ class CastSuite extends CastSuiteBase {
test("SPARK-36286: invalid string cast to timestamp") {
checkEvaluation(cast(Literal("2015-03-18T"), TimestampType), null)
}
+
+ test("SPARK-36924: Cast DayTimeIntervalType to IntegralType") {
+ DataTypeTestUtils.dayTimeIntervalTypes.foreach { dt =>
+ val v1 = Literal.create(Duration.ZERO, dt)
+ checkEvaluation(cast(v1, ByteType), 0.toByte)
+ checkEvaluation(cast(v1, ShortType), 0.toShort)
+ checkEvaluation(cast(v1, IntegerType), 0)
+ checkEvaluation(cast(v1, LongType), 0L)
+
+ val num = SECONDS_PER_DAY + SECONDS_PER_HOUR + SECONDS_PER_MINUTE + 1
+ val v2 = Literal.create(Duration.ofSeconds(num), dt)
+ dt.endField match {
+ case DAY =>
+ checkEvaluation(cast(v2, ByteType), 1.toByte)
+ checkEvaluation(cast(v2, ShortType), 1.toShort)
+ checkEvaluation(cast(v2, IntegerType), 1)
+ checkEvaluation(cast(v2, LongType), 1L)
+ case HOUR =>
+ checkEvaluation(cast(v2, ByteType), 25.toByte)
+ checkEvaluation(cast(v2, ShortType), 25.toShort)
+ checkEvaluation(cast(v2, IntegerType), 25)
+ checkEvaluation(cast(v2, LongType), 25L)
+ case MINUTE =>
+ val e = intercept[ArithmeticException] {
+ cast(v2, ByteType).eval()
+ }.getMessage
+ assert(e.contains(s"Casting 90060000000 to tinyint causes overflow"))
Review comment:
shall we use interval value string instead of `90060000000`?
--
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]