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-35727][SQL] Return INTERVAL DAY from dates subtraction #32999
Conversation
cc @MaxGekk |
Can one of the admins verify this patch? |
if (legacyInterval) { | ||
CalendarIntervalType | ||
} else { | ||
DayTimeIntervalType(DayTimeIntervalType.DAY, DayTimeIntervalType.DAY) |
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 have added apply()
with single arg recently #32997, you can use it here as:
DayTimeIntervalType(DAY)
checkAnswer(df.select($"end" - $"start"), Row(daysBetween)) | ||
val r = df.select($"end" - $"start").toDF("diff") | ||
checkAnswer(r, Row(daysBetween)) | ||
assert(r.schema === new StructType().add("diff", DayTimeIntervalType(0, 0))) |
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.
Please, replace DayTimeIntervalType(0, 0)
by DayTimeIntervalType(DAY)
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.
@Peng-Lei This change seems to include the change not only for Date - Date
but also Date + Interval
and Interval + Date
. If you'd like to include them, could you add tests for them too?
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.
Let's exclude the Date +/- Interval
changes from this PR.
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.
could you add tests for them too
@sarutak ,Sorry I am wrong. First I should exclude the Date +/- Interval
from this PR. Second Even if I wanted to change Date +/- Interval
, I should convert the interval to the number of days ExtractANSIIntervalDays)
and then use DateAdd
expression as cloud-fan said.
Also cc @sarutak @AngersZhuuuu and @cloud-fan |
@Peng-Lei |
@@ -349,8 +349,18 @@ class Analyzer(override val catalogManager: CatalogManager) | |||
case p: LogicalPlan => p.transformExpressionsUpWithPruning( | |||
_.containsPattern(BINARY_ARITHMETIC), ruleId) { | |||
case a @ Add(l, r, f) if a.childrenResolved => (l.dataType, r.dataType) match { | |||
case (DateType, _: DayTimeIntervalType) => TimeAdd(Cast(l, TimestampType), r) | |||
case (_: DayTimeIntervalType, DateType) => TimeAdd(Cast(r, TimestampType), l) | |||
case (DateType, dit: DayTimeIntervalType) => |
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 change in Analyzer.scala
doesn't seem related to the issue raised in SPARK-35727.
If we define the arithmetic operations between DateType
and DayTimeIntervalType
, we should define such operators for YearMonthIntervalType
right?
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 agree with change but I think it's a separate thing and can be done in a new PR.
The impl detail can also be improved: we can convert the interval to the number of days (ExtractANSIIntervalDays
) and then use DateAdd
expression.
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 agree with change but I think it's a separate thing and can be done in a new PR.
The impl detail can also be improved: we can convert the interval to the number of days (
ExtractANSIIntervalDays
) and then useDateAdd
expression.
@cloud-fan Could I propose a ticket for improved for DateType +/- DayTimeIntervalType(DAY)
and try to resolve it ?
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 please
734b6e2
to
525eb9e
Compare
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 if all checks pass (scalastyle check will fail I think)
@cloud-fan Thank you very much. Your review comments are always inspiring. |
@Peng-Lei Could you fix markdown in PR's description. Please, keep the original formatting for sections. |
if (legacyInterval) { | ||
CalendarIntervalType | ||
} else { | ||
DayTimeIntervalType(DAY) | ||
} |
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: minimal changes would be:
if (legacyInterval) CalendarIntervalType else DayTimeIntervalType(DAY)
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.
@MaxGekk Thank you very much, I fix it. Thank you.
@Peng-Lei The failed tests:
are related to the changes. Could you regenerate the golden files, please. |
@MaxGekk ok. I'm working on how to do this, |
@Peng-Lei you can check the classdoc of |
thanks, merging to master! |
@Peng-Lei Could you change formatting of PR's description (see #32999 (comment)), please. It has been already late for the commit but in any case. |
Yeah, let's keep the PR description properly. |
@MaxGekk Sorry, I missed that comment #32999 (comment), I will pay more attention to PR description and deal with each review comments of PR in the future. Thank you. |
@Peng-Lei although it's merged, you can still update the PR description, in case other people come to this PR in the future |
What changes were proposed in this pull request?
Change the return value type from
DayTimeIntervalType(DAY, SECOND)
toDayTimeIntervalType(DAY, DAY)
ofSubtractDates
.Why are the changes needed?
SPARK-35727
Does this PR introduce any user-facing change?
No
How was this patch tested?
existed ut test