-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25056][SQL] Unify the InConversion and BinaryComparison behavior #22038
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
9459e6e
c4775c4
935ed36
cb25b78
4fd2143
48abf9f
20bdc95
87ab27e
80adb74
7c56d38
232e42f
8536af4
b1958dd
f060efa
e60ff29
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 |
|---|---|---|
|
|
@@ -415,13 +415,6 @@ object TypeCoercion { | |
| if left.dataType != CalendarIntervalType => | ||
| a.makeCopy(Array(left, Cast(right, DoubleType))) | ||
|
|
||
| // For equality between string and timestamp we cast the string to a timestamp | ||
| // so that things like rounding of subsecond precision does not affect the comparison. | ||
| case p @ Equality(left @ StringType(), right @ TimestampType()) => | ||
| p.makeCopy(Array(Cast(left, TimestampType), right)) | ||
| case p @ Equality(left @ TimestampType(), right @ StringType()) => | ||
| p.makeCopy(Array(left, Cast(right, TimestampType))) | ||
|
|
||
| case p @ BinaryComparison(left, right) | ||
| if findCommonTypeForBinaryComparison(left.dataType, right.dataType, conf).isDefined => | ||
| val commonType = findCommonTypeForBinaryComparison(left.dataType, right.dataType, conf).get | ||
|
|
@@ -491,10 +484,21 @@ object TypeCoercion { | |
| i | ||
| } | ||
|
|
||
| case i @ In(a, b) if b.exists(_.dataType != a.dataType) => | ||
| findWiderCommonType(i.children.map(_.dataType)) match { | ||
| case Some(finalDataType) => i.withNewChildren(i.children.map(Cast(_, finalDataType))) | ||
| case None => i | ||
| case i @ In(value, list) if list.exists(_.dataType != value.dataType) => | ||
| if (conf.getConf(SQLConf.LEGACY_IN_PREDICATE_FOLLOW_BINARY_COMPARISON_TYPE_COERCION)) { | ||
| findWiderCommonType(list.map(_.dataType)) match { | ||
| case Some(listType) => | ||
| val finalDataType = findCommonTypeForBinaryComparison(value.dataType, listType, conf) | ||
|
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. @wangyum, the behaviours between decimals and strings look good. But what about other types affected here? If we think about interpreting // For equality between string and timestamp we cast the string to a timestamp
// so that things like rounding of subsecond precision does not affect the comparison.
case p @ Equality(left @ StringType(), right @ TimestampType()) =>
p.makeCopy(Array(Cast(left, TimestampType), right))
case p @ Equality(left @ TimestampType(), right @ StringType()) =>
p.makeCopy(Array(left, Cast(right, TimestampType)))What do you think about fixing this issue completely rather than fixing cases one by one? I didn't check ANSI or other DBMSs yet but I know
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. We can remove TypeCoercion.scala#L418-L423 because we have added the same logic to |
||
| .orElse(findWiderTypeForDecimal(value.dataType, listType)) | ||
| .orElse(findTightestCommonType(value.dataType, listType)) | ||
| finalDataType.map(t => i.withNewChildren(i.children.map(Cast(_, t)))).getOrElse(i) | ||
| case None => i | ||
| } | ||
| } else { | ||
| findWiderCommonType(i.children.map(_.dataType)) match { | ||
| case Some(finalDataType) => i.withNewChildren(i.children.map(Cast(_, finalDataType))) | ||
| case None => i | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.