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
[SPARK-29783][SQL] Support SQL Standard/ISO_8601 output style for interval type #26418
Closed
Closed
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
88418e0
[SPARK-29783][SQL] Support SQL Standard output style for interval type
yaooqinn 02be22b
Merge branch 'master' into SPARK-29783
yaooqinn 429ee49
Merge branch 'master' into SPARK-29783
yaooqinn da119c5
Merge branch 'master' into SPARK-29783
yaooqinn fff17d5
add a sep conf
yaooqinn 2af8593
Merge remote-tracking branch 'origin/master' into SPARK-29783
yaooqinn b3c9e08
add support for iso_8601 output
yaooqinn 005a28d
add ut
yaooqinn 5ea0ff8
mv calendar interval toString to utils
yaooqinn fa9c41e
fix java style
yaooqinn f89e7c1
fix test case
yaooqinn 981eae5
to json support and fix toSqlStandardString bug
yaooqinn be65a4d
make sql standard output format explicitly
yaooqinn 748fbad
regen golden file
yaooqinn 3aa723c
rm json support / change config name / other minor revisions
yaooqinn 0f54bac
Merge remote-tracking branch 'origin/master' into SPARK-29783
yaooqinn 3cf71e9
regen golden file
yaooqinn 8d18fac
rm json part change and change config back
yaooqinn 0c530cc
import
yaooqinn 08b7359
Merge remote-tracking branch 'origin/master' into SPARK-29783
yaooqinn 7641e5e
create interval-display*.sql
yaooqinn 0f54af8
blacklisting new tests in thrift test
yaooqinn File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
package org.apache.spark.sql.catalyst.util | ||
|
||
import java.math.BigDecimal | ||
import java.util.concurrent.TimeUnit | ||
|
||
import scala.util.control.NonFatal | ||
|
@@ -391,6 +392,43 @@ object IntervalUtils { | |
fromDoubles(interval.months / num, interval.days / num, interval.microseconds / num) | ||
} | ||
|
||
def toSqlStandardString(interval: CalendarInterval): String = { | ||
yaooqinn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val yearMonthPart = if (interval.months != 0) { | ||
interval.months / 12 + "-" + math.abs(interval.months) % 12 | ||
} else { | ||
"" | ||
} | ||
|
||
val dayPart = if (interval.days != 0) interval.days.toString else "" | ||
|
||
val timePart = if (interval.microseconds != 0) { | ||
val sb = new StringBuilder() | ||
var rest = interval.microseconds | ||
sb.append(rest / MICROS_PER_HOUR) | ||
sb.append(':') | ||
rest = math.abs(rest % MICROS_PER_HOUR) | ||
val minutes = rest / MICROS_PER_MINUTE; | ||
if (minutes < 10) { | ||
sb.append(0) | ||
} | ||
sb.append(minutes) | ||
sb.append(':') | ||
rest %= MICROS_PER_MINUTE | ||
val db = BigDecimal.valueOf(rest, 6) | ||
if (db.compareTo(new BigDecimal(10)) < 0) { | ||
sb.append(0) | ||
} | ||
val s = db.stripTrailingZeros().toPlainString | ||
sb.append(s) | ||
sb.toString() | ||
} else { | ||
"" | ||
} | ||
|
||
val intervalList = Seq(yearMonthPart, dayPart, timePart).filter(_.nonEmpty) | ||
if (intervalList.nonEmpty) intervalList.mkString(" ") else "0" | ||
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. wow, a single 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. postgres=# set IntervalStyle=sql_standard;
SET
postgres=# select interval '0';
interval
----------
0
(1 row)
postgres=# set IntervalStyle=postgres;
SET
postgres=# select interval '0';
interval
----------
00:00:00
(1 row) |
||
} | ||
|
||
private object ParseState extends Enumeration { | ||
val PREFIX, | ||
BEGIN_VALUE, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be something that can be parsed, I think we need to output something like
INTERVAL'1 year 2 days'
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.
We don't support SQL standard input for intervals? I missed that, may cause user behavior change. But If we stay multi-unit style here, would there be conflicting between literals and other exprs?
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.
changed back , thanks