andygrove opened a new issue, #388:
URL: https://github.com/apache/datafusion-spark/issues/388

   ## Is your feature request related to a problem or challenge?
   
   Spark's `ComplexTypeMergingExpression` covers expressions whose result type 
is the common type of several children, such as `coalesce`, `greatest`, 
`least`, `if`, `case when`, `array(...)`, `map(...)`, `nvl` and `nvl2`. Spark 
computes that type with `findWiderCommonType` (or 
`findWiderTypeWithoutStringPromotion`). In ANSI mode it uses the 
`AnsiTypeCoercion` variants instead.
   
   `type_coercion.rs` only has `tightest_common_type`. Because of that:
   
   - `if` uses DataFusion's `try_type_union_resolution`
   - `array` uses `make_array`'s `coerce_types_inner`
   - `equal_null` uses DataFusion's `comparison_coercion`
   
   These differ from Spark for decimals of different precision and scale, 
integer and decimal mixes, string promotion, and nested types.
   
   ## Describe the solution you'd like
   
   - Port `findWiderCommonType` and `findWiderTypeWithoutStringPromotion`, with 
their ANSI versions, into `type_coercion.rs`.
   - Add a small helper for type-merging functions that computes the common 
type of the arguments (all of them, or a given range), casts each argument to 
it, and raises Spark's `DATATYPE_MISMATCH.DATA_DIFF_TYPES` error otherwise.
   - Move `if`, `array` and later `coalesce`/`greatest`/`least`/`nvl`/`nvl2` 
onto the helper.
   
   ## Describe alternatives you've considered
   
   Keep DataFusion's rules. They are close, but they produce different result 
types in the cases above.
   
   ## Additional context
   
   The "Common type rules" item in #353 depends on this. Follows on from #345 
and #346.
   


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to