-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-34668][SQL] Support casting of day-time intervals to strings #32070
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 starting |
|
Kubernetes integration test status failure |
|
Test build #136965 has finished for PR 32070 at commit
|
| Duration.ofMillis(1234) -> "0 0:0:1.234", | ||
| Duration.ofSeconds(-59).minus(999999, ChronoUnit.MICROS) -> "-0 0:0:59.999999", | ||
| Duration.ofMinutes(30).plusMillis(10) -> "0 0:30:0.01", | ||
| Duration.ofHours(-23).minusSeconds(59) -> "-0 23:0:59", |
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 times, I think it's more common to always have 2 digits. Have we checked with other databases?
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.
Have we checked with other databases?
For example, Oracle doesn't prepend zero for hours, see the doc:
INTERVAL '4 5:12:10.222' DAY TO SECOND
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.
that's the literal syntax, which is supposed to be more flexible. How about the cast behavior?
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.
added leading zeros for time parts
|
@cloud-fan @gengliangwang @yaooqinn @AngersZhuuuu Could you review this PR, please. |
| val hours = rest % HOURS_PER_DAY | ||
| val days = rest / HOURS_PER_DAY | ||
| s"INTERVAL '$sign$days $hours:$minutes:$secondStr' DAY TO SECOND" | ||
| val leadSecZero = if (seconds < 10000000) "0" else "" |
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.
nit: use MICROS_PER_SECONDS?
yaooqinn
left a comment
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.
LGTM as always
| var sign = "" | ||
| var rest = micros | ||
| if (micros < 0) { | ||
| if (micros == Long.MinValue) { |
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.
nice catch!
gengliangwang
left a comment
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.
LGTM
AngersZhuuuu
left a comment
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.
LGTM
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
|
Test build #137012 has finished for PR 32070 at commit
|
|
Test build #137020 has finished for PR 32070 at commit
|
|
Refer to this link for build results (access rights to CI server needed): |
|
thanks, merging to master! |
What changes were proposed in this pull request?
toDayTimeIntervalString()toIntervalUtilswhich converts a day-time interval as a number of microseconds to a string in the form "INTERVAL '[sign]days hours:minutes:secondsWithFraction' DAY TO SECOND".Castexpression to support casting ofDayTimeIntervalTypetoStringType.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 day-time interval has not been released yet.
How was this patch tested?
Added new tests for casting: