-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-34667][SQL] Support casting of year-month intervals to strings #32056
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
Conversation
|
Kubernetes integration test unable to build dist. exiting with code: 1 |
|
Test build #136921 has finished for PR 32056 at commit
|
|
@gengliangwang @cloud-fan @yaooqinn @AngersZhuuuu Could you review this PR, please. |
| sign = "-" | ||
| absMonths = -absMonths | ||
| } | ||
| s"interval '$sign${absMonths / MONTHS_PER_YEAR}-${absMonths % MONTHS_PER_YEAR}' year to month" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last part "year to month" looks a bit confusing to me. What does other DBMS systems do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last part "year to month" looks a bit confusing to me
This part conforms to the SQL standard, see:
<interval literal> ::=
INTERVAL [ <sign> ] <interval string> <interval qualifier>
<interval qualifier> ::=
<start field> TO <end field>
| <single datetime field>
<start field> ::=
<non-second primary datetime field>
[ <left paren> <interval leading field precision> <right paren> ]
<end field> ::=
<non-second primary datetime field>
| SECOND [ <left paren> <interval fractional seconds precision> <right paren> ]
<single datetime field> ::= <non-second primary datetime field>
[ <left paren> <interval leading field precision> <right paren> ]
| SECOND [ <left paren> <interval leading field precision>
[ <comma> <interval fractional seconds precision> ] <right paren> ]
<primary datetime field> ::= <non-second primary datetime field>
| SECOND
<non-second primary datetime field> ::= YEAR
| MONTH
| DAY
| HOUR
| MINUTE
<interval string> ::=
<quote> <unquoted interval string> <quote>
<unquoted interval string> ::=
[ <sign> ] { <year-month literal> | <day-time literal> }
What does other DBMS systems do?
For instance, see Oracle https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/Literals.html#GUID-4C258D8F-3DF2-4D45-BE3E-14864DD77100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for the explanation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the standard, it seems the output of "-13 months" should be
interval - '1-1' year to month
instead of
interval '-1-1' year to month
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are allowed by the standard. See the grammar rules:
<unquoted interval string> ::=
[ <sign> ] { <year-month literal> | <day-time literal> }
<interval literal> ::=
INTERVAL [ <sign> ] <interval string> <interval qualifier>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Shall we add one space in between the sign and interval string as per the standard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
Outdated
Show resolved
Hide resolved
|
Looks good to me except two comments. |
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
|
Test build #136938 has finished for PR 32056 at commit
|
|
Merging to master. Thank you @gengliangwang @cloud-fan and @yaooqinn for your reviews. |
|
Test build #136939 has finished for PR 32056 at commit
|

What changes were proposed in this pull request?
toYearMonthIntervalString()toIntervalUtilswhich converts an year-month interval as a number of month to a string in the form "INTERVAL '[sign]yearField-monthField' YEAR TO MONTH".Castexpression to support casting ofYearMonthIntervalTypetoStringType.Why are the changes needed?
To conform the ANSI SQL standard which requires to support such casting.
Does this PR introduce any user-facing change?
Should not because new year-month interval has not been released yet.
How was this patch tested?
Added new tests for casting: