wangyum commented on a change in pull request #22038: [SPARK-25056][SQL] Unify 
the InConversion and BinaryComparison behavior
URL: https://github.com/apache/spark/pull/22038#discussion_r346227356
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
 ##########
 @@ -495,9 +495,12 @@ 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 i @ In(value, list) if list.exists(_.dataType != value.dataType) =>
+        findWiderCommonType(list.map(_.dataType)) match {
 
 Review comment:
   ```
   findTightestCommonType(value.dataType, 
listType).orElse(findCommonTypeForBinaryComparison(value.dataType, listType, 
conf))
   ```
   Can not cover these cases:
   
   - `bigint` vs `decimal`
   - `float` vs `decimal`
   - `double` vs `decimal`
   
   Example:
   ```
   -- !query 43
   SELECT cast(1 as bigint) in (cast(1 as decimal(10, 0))) FROM t
   -- !query 43 schema
   struct<>
   -- !query 43 output
   org.apache.spark.sql.AnalysisException
   cannot resolve '(CAST(1 AS BIGINT) IN (CAST(1 AS DECIMAL(10,0))))' due to 
data type mismatch: Arguments must be same type but were: bigint != 
decimal(10,0); line 1 pos 25
   
   ```
   ```
   spark-sql> explain SELECT cast(1 as bigint) > (cast(1 as decimal(10, 0)));
   == Physical Plan ==
   *(1) Project [false AS (CAST(CAST(CAST(1 AS BIGINT) AS DECIMAL(20,0)) AS 
DECIMAL(20,0)) > CAST(CAST(1 AS DECIMAL(10,0)) AS DECIMAL(20,0)))#29]
   +- *(1) Scan OneRowRelation[]
   ```

----------------------------------------------------------------
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]

Reply via email to