-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-35111][SQL] Support Cast string to year-month interval #32266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9546a0f
691c1f4
f5b02ee
15424a7
879817b
62d175b
2c75bba
5b134fa
6d14414
d19bbc8
ff904a1
d0e30e4
3b84baa
b05f7e6
25c08e0
f636d41
ce69004
092d01a
f088f64
80499b8
ca19c09
3df92b6
3adde87
0f82987
2c8785b
253c70e
9c70b88
5ca83ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1774,6 +1774,48 @@ class CastSuite extends CastSuiteBase { | |
| assert(e3.contains("Casting 2147483648 to int causes overflow")) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-35111: Cast string to year-month interval") { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add round trip tests: string -> year-month interval -> string, and year-month interval -> string -> year-month interval
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you test corner cases when arithmetic overflow happens. Also test upper and lower cases.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, check the input in lower case. For example: checkEvaluation(cast(Literal.create(" interval '1-0' YEAR TO MONTH "),
YearMonthIntervalType), 12) |
||
| checkEvaluation(cast(Literal.create("INTERVAL '1-0' YEAR TO MONTH"), | ||
| YearMonthIntervalType), 12) | ||
| checkEvaluation(cast(Literal.create("INTERVAL '-1-0' YEAR TO MONTH"), | ||
| YearMonthIntervalType), -12) | ||
| checkEvaluation(cast(Literal.create("INTERVAL -'-1-0' YEAR TO MONTH"), | ||
| YearMonthIntervalType), 12) | ||
| checkEvaluation(cast(Literal.create("INTERVAL +'-1-0' YEAR TO MONTH"), | ||
| YearMonthIntervalType), -12) | ||
| checkEvaluation(cast(Literal.create("INTERVAL +'+1-0' YEAR TO MONTH"), | ||
| YearMonthIntervalType), 12) | ||
| checkEvaluation(cast(Literal.create("INTERVAL +'1-0' YEAR TO MONTH"), | ||
| YearMonthIntervalType), 12) | ||
| checkEvaluation(cast(Literal.create(" interval +'1-0' YEAR TO MONTH "), | ||
| YearMonthIntervalType), 12) | ||
| checkEvaluation(cast(Literal.create(" -1-0 "), YearMonthIntervalType), -12) | ||
| checkEvaluation(cast(Literal.create("-1-0"), YearMonthIntervalType), -12) | ||
| checkEvaluation(cast(Literal.create(null, StringType), YearMonthIntervalType), null) | ||
|
|
||
| Seq("0-0", "10-1", "-178956970-7", "178956970-7", "-178956970-8").foreach { interval => | ||
| val ansiInterval = s"INTERVAL '$interval' YEAR TO MONTH" | ||
| checkEvaluation( | ||
| cast(cast(Literal.create(interval), YearMonthIntervalType), StringType), ansiInterval) | ||
| checkEvaluation(cast(cast(Literal.create(ansiInterval), | ||
| YearMonthIntervalType), StringType), ansiInterval) | ||
| } | ||
|
|
||
| Seq("INTERVAL '-178956970-9' YEAR TO MONTH", "INTERVAL '178956970-8' YEAR TO MONTH") | ||
| .foreach { interval => | ||
| val e = intercept[IllegalArgumentException] { | ||
| cast(Literal.create(interval), YearMonthIntervalType).eval() | ||
| }.getMessage | ||
| assert(e.contains("Error parsing interval year-month string: integer overflow")) | ||
| } | ||
|
|
||
| Seq(Byte.MaxValue, Short.MaxValue, Int.MaxValue, Int.MinValue + 1, Int.MinValue) | ||
| .foreach { period => | ||
| val interval = Literal.create(Period.ofMonths(period), YearMonthIntervalType) | ||
| checkEvaluation(cast(cast(interval, StringType), YearMonthIntervalType), period) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.