-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-42991][SQL] Disable string type +/- interval in ANSI mode #40616
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 |
|---|---|---|
|
|
@@ -836,6 +836,7 @@ object TypeCoercion extends TypeCoercionBase { | |
| UnpivotCoercion :: | ||
| WidenSetOperationTypes :: | ||
| new CombinedTypeCoercionRule( | ||
| ResolveBinaryArithmetic :: | ||
| InConversion :: | ||
| PromoteStrings :: | ||
| DecimalPrecision :: | ||
|
|
@@ -1170,6 +1171,29 @@ object TypeCoercion extends TypeCoercionBase { | |
| } | ||
| } | ||
|
|
||
| // For legacy support. For example: string type +/- interval. | ||
| object ResolveBinaryArithmetic extends TypeCoercionRule { | ||
| override val transform: PartialFunction[Expression, Expression] = | ||
| AnsiTypeCoercion.ResolveBinaryArithmetic.transform.andThen { | ||
| case a @ Add(l, r, _) if a.childrenResolved => (l.dataType, r.dataType) match { | ||
| case (StringType | _: NumericType | BinaryType | BooleanType, | ||
| CalendarIntervalType | _: DayTimeIntervalType) => | ||
| Cast(TimeAdd(l, r), l.dataType) | ||
|
Member
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 first child of
Member
Author
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. For ANSI mode. It should be DatetimeType and AnsiIntervalType: |
||
| case (CalendarIntervalType | _: DayTimeIntervalType, | ||
| StringType | _: NumericType | BinaryType | BooleanType) => | ||
| Cast(TimeAdd(r, l), r.dataType) | ||
| case _ => a | ||
| } | ||
| case s @ Subtract(l, r, mode) if s.childrenResolved => (l.dataType, r.dataType) match { | ||
| case (StringType | _: NumericType | BinaryType | BooleanType, | ||
| CalendarIntervalType | _: DayTimeIntervalType) => | ||
| Cast(DatetimeSub(l, r, TimeAdd(l, UnaryMinus(r, mode == EvalMode.ANSI))), l.dataType) | ||
| case _ => s | ||
| } | ||
| case other => other | ||
| } | ||
| } | ||
|
|
||
| object DateTimeOperations extends TypeCoercionRule { | ||
| override val transform: PartialFunction[Expression, Expression] = { | ||
| // Skip nodes who's children have not been resolved yet. | ||
|
|
||
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.
is it possible to do some code sharing?
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. Updated the code:
https://github.com/apache/spark/blob/cd21cce9131e17d53b164fdfe8d54a59a265f41a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala#L1173-L1194