-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-30189][SQL] Interval from year-month/date-time string should handle whitespaces #26815
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
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 85 | ||
| -- Number of queries: 89 | ||
|
|
||
|
|
||
| -- !query | ||
|
|
@@ -804,6 +804,51 @@ struct<INTERVAL '1 days':interval> | |
| 1 days | ||
|
|
||
|
|
||
| -- !query | ||
| select interval '2-2\t' year to month | ||
| -- !query schema | ||
| struct<INTERVAL '2 years 2 months':interval> | ||
| -- !query output | ||
| 2 years 2 months | ||
|
|
||
|
|
||
| -- !query | ||
| select interval '-\t2-2\t' year to month | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| Interval string does not match year-month format of 'y-m': - 2-2 (line 1, pos 16) | ||
|
|
||
| == SQL == | ||
| select interval '-\t2-2\t' year to month | ||
| ----------------^^^ | ||
|
|
||
|
|
||
| -- !query | ||
| select interval '\n0 12:34:46.789\t' day to second | ||
| -- !query schema | ||
| struct<INTERVAL '12 hours 34 minutes 46.789 seconds':interval> | ||
| -- !query output | ||
| 12 hours 34 minutes 46.789 seconds | ||
|
|
||
|
|
||
| -- !query | ||
| select interval '\n-\t10\t 12:34:46.789\t' day to second | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| requirement failed: Interval string must match day-time format of '^(?<sign>[+|-])?(?<day>\d+) (?<hour>\d{1,2}):(?<minute>\d{1,2}):(?<second>(\d{1,2})(\.(\d{1,9}))?)$': | ||
| - 10 12:34:46.789 , set spark.sql.legacy.fromDayTimeString.enabled to true to restore the behavior before Spark 3.0.(line 1, pos 16) | ||
|
Contributor
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. not related to this PR, but we should only ask users to set the legacy config if it works. |
||
|
|
||
| == SQL == | ||
| select interval '\n-\t10\t 12:34:46.789\t' day to second | ||
| ----------------^^^ | ||
|
|
||
|
|
||
| -- !query | ||
| select -(a) from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) | ||
| -- !query schema | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
|
Contributor
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. not related to this PR: we should put the test queries that have different behaviors if ansi mode is on to a different file, and only test that file with ansi mode on and off. |
||
| -- Number of queries: 85 | ||
| -- Number of queries: 89 | ||
|
|
||
|
|
||
| -- !query | ||
|
|
@@ -783,6 +783,51 @@ struct<INTERVAL '1 days':interval> | |
| 1 days | ||
|
|
||
|
|
||
| -- !query | ||
| select interval '2-2\t' year to month | ||
| -- !query schema | ||
| struct<INTERVAL '2 years 2 months':interval> | ||
| -- !query output | ||
| 2 years 2 months | ||
|
|
||
|
|
||
| -- !query | ||
| select interval '-\t2-2\t' year to month | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| Interval string does not match year-month format of 'y-m': - 2-2 (line 1, pos 16) | ||
|
|
||
| == SQL == | ||
| select interval '-\t2-2\t' year to month | ||
| ----------------^^^ | ||
|
|
||
|
|
||
| -- !query | ||
| select interval '\n0 12:34:46.789\t' day to second | ||
| -- !query schema | ||
| struct<INTERVAL '12 hours 34 minutes 46.789 seconds':interval> | ||
| -- !query output | ||
| 12 hours 34 minutes 46.789 seconds | ||
|
|
||
|
|
||
| -- !query | ||
| select interval '\n-\t10\t 12:34:46.789\t' day to second | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| requirement failed: Interval string must match day-time format of '^(?<sign>[+|-])?(?<day>\d+) (?<hour>\d{1,2}):(?<minute>\d{1,2}):(?<second>(\d{1,2})(\.(\d{1,9}))?)$': | ||
| - 10 12:34:46.789 , set spark.sql.legacy.fromDayTimeString.enabled to true to restore the behavior before Spark 3.0.(line 1, pos 16) | ||
|
|
||
| == SQL == | ||
| select interval '\n-\t10\t 12:34:46.789\t' day to second | ||
| ----------------^^^ | ||
|
|
||
|
|
||
| -- !query | ||
| select -(a) from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) | ||
| -- !query schema | ||
|
|
||
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.
for multi-unit syntax, do we support
1 day \t 2 hours?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.
yes. My opinion is that the interval string in multi-unit syntax, we parse each value and each unit separately and they can be produced by the providers separately too so the whitespaces can be in the middle of each part. In year-month and day-time syntax, the string should be considered as a whole part so the whitespaces only appear on both ends, not in the middle.
take java.sql.Timestamp for an example, the timestamp string is treated as a whole
Also, we do the same in Spark