Gengliang Wang created SPARK-34769:
--------------------------------------

             Summary: AnsiTypeCoercion: return narrowest convertible type among 
TypeCollection
                 Key: SPARK-34769
                 URL: https://issues.apache.org/jira/browse/SPARK-34769
             Project: Spark
          Issue Type: Sub-task
          Components: SQL
    Affects Versions: 3.2.0
            Reporter: Gengliang Wang
            Assignee: Gengliang Wang


Currently, when implicit casting a data type to a `TypeCollection`, Spark 
returns the first convertible data type among `TypeCollection`.
In ANSI mode, we can make the behavior more reasonable by returning the 
narrowest convertible data type in `TypeCollection`.

In details,  we first try to find the all the expected types we can implicitly 
cast:
1. if there is no convertible data types, return None;
2. if there is only one convertible data type, cast input as it;
3. otherwise if there are multiple convertible data types, find the narrowest 
common data
     type among them. If there is no such narrowest common data type, return 
None.

Note that if the narrowest common type is Float type and the convertible types 
contains Double ype, simply return Double type as the narrowest common type to 
avoid potential
 precision loss on converting the Integral type as Float type.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to