-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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-34761][SQL] Support add/subtract of a day-time interval to/from a timestamp #31855
Changes from all commits
e4b299d
90c46af
92a855b
1868930
a14e90a
6cce729
5833bd0
c861a17
84af890
66874b6
c851449
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 |
---|---|---|
|
@@ -342,11 +342,12 @@ class Analyzer(override val catalogManager: CatalogManager) | |
case (YearMonthIntervalType, DateType) => DateAddYMInterval(r, l) | ||
case (TimestampType, YearMonthIntervalType) => TimestampAddYMInterval(l, r) | ||
case (YearMonthIntervalType, TimestampType) => TimestampAddYMInterval(r, l) | ||
case (CalendarIntervalType, CalendarIntervalType) => a | ||
case (CalendarIntervalType, CalendarIntervalType) | | ||
(DayTimeIntervalType, DayTimeIntervalType) => a | ||
case (DateType, CalendarIntervalType) => DateAddInterval(l, r, ansiEnabled = f) | ||
case (_, CalendarIntervalType) => Cast(TimeAdd(l, r), l.dataType) | ||
case (_, CalendarIntervalType | DayTimeIntervalType) => Cast(TimeAdd(l, r), l.dataType) | ||
case (CalendarIntervalType, DateType) => DateAddInterval(r, l, ansiEnabled = f) | ||
case (CalendarIntervalType, _) => Cast(TimeAdd(r, l), r.dataType) | ||
case (CalendarIntervalType | DayTimeIntervalType, _) => Cast(TimeAdd(r, l), r.dataType) | ||
case (DateType, dt) if dt != StringType => DateAdd(l, r) | ||
case (dt, DateType) if dt != StringType => DateAdd(r, l) | ||
case _ => a | ||
|
@@ -356,10 +357,11 @@ class Analyzer(override val catalogManager: CatalogManager) | |
DatetimeSub(l, r, DateAddYMInterval(l, UnaryMinus(r, f))) | ||
case (TimestampType, YearMonthIntervalType) => | ||
DatetimeSub(l, r, TimestampAddYMInterval(l, UnaryMinus(r, f))) | ||
case (CalendarIntervalType, CalendarIntervalType) => s | ||
case (CalendarIntervalType, CalendarIntervalType) | | ||
(DayTimeIntervalType, DayTimeIntervalType) => s | ||
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. ditto 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. The |
||
case (DateType, CalendarIntervalType) => | ||
DatetimeSub(l, r, DateAddInterval(l, UnaryMinus(r, f), ansiEnabled = f)) | ||
case (_, CalendarIntervalType) => | ||
case (_, CalendarIntervalType | DayTimeIntervalType) => | ||
Cast(DatetimeSub(l, r, TimeAdd(l, UnaryMinus(r, f))), l.dataType) | ||
case (TimestampType, _) => SubtractTimestamps(l, r) | ||
case (_, TimestampType) => SubtractTimestamps(l, r) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,13 +164,10 @@ object LiteralGenerator { | |
for { i <- Gen.choose(-100, 100) } yield Literal.create(i, IntegerType) | ||
|
||
lazy val dayTimeIntervalLiteralGen: Gen[Literal] = { | ||
for { | ||
seconds <- Gen.choose( | ||
Duration.ofDays(-106751990).getSeconds, | ||
Duration.ofDays(106751990).getSeconds) | ||
nanoAdjustment <- Gen.choose(-999999000, 999999000) | ||
} yield { | ||
Literal.create(Duration.ofSeconds(seconds, nanoAdjustment), DayTimeIntervalType) | ||
calendarIntervalLiterGen.map { calendarIntervalLiteral => | ||
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. This generator is used to test expressions like |
||
Literal.create( | ||
calendarIntervalLiteral.value.asInstanceOf[CalendarInterval].extractAsDuration(), | ||
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.
shall we allow adding year-month interval as well?
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 op is allowed already, see the test https://github.com/apache/spark/pull/31789/files#diff-bff10c8a3182aa943d8927135e0c14b02a338d9bcca94ddcd77670ee01fea0f3R2380 . It should still pass after the changes.
I have to add this cases because I reuse the
TimeAdd
expression, and associated rules here.The
year-month interval
+/-year-month interval
expr is handled by the default casecase _ => a
/case _ => s
.