liancheng commented on a change in pull request #26485: [SPARK-29860][SQL] Fix
dataType mismatch issue for InSubquery.
URL: https://github.com/apache/spark/pull/26485#discussion_r353539018
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
##########
@@ -472,9 +472,12 @@ object TypeCoercion {
// RHS is the subquery output.
val rhs = sub.output
- val commonTypes = lhs.zip(rhs).flatMap { case (l, r) =>
- findCommonTypeForBinaryComparison(l.dataType, r.dataType, conf)
- .orElse(findTightestCommonType(l.dataType, r.dataType))
+ val commonTypes = lhs.zip(rhs).flatMap {
+ case (l, r) if !l.dataType.isInstanceOf[DecimalType] &&
+ !r.dataType.isInstanceOf[DecimalType] =>
+ findCommonTypeForBinaryComparison(l.dataType, r.dataType, conf)
+ .orElse(findTightestCommonType(l.dataType, r.dataType))
+ case (l, r) => findWiderTypeForDecimal(l.dataType, r.dataType)
Review comment:
We can clean this part a little bit with the extractor defined in `object
DecimalType` for checking expression data types:
```scala
val commonTypes = lhs.zip(rhs).flatMap {
case (l @ DecimalType(), r @ DecimalType()) =>
findWiderTypeForDecimal(l.dataType, r.dataType)
case (l, r) =>
findCommonTypeForBinaryComparison(l.dataType, r.dataType, conf).orElse {
findTightestCommonType(l.dataType, r.dataType)
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]