zZKato opened a new issue, #9098:
URL: https://github.com/apache/arrow-datafusion/issues/9098

   ### Describe the bug
   
   When coalescing between two arrays, datafusion will infer the type to be 
Utf8.
   
   ### To Reproduce
   
   ```
   ❯ select arrow_typeof(coalesce([1], [2]));
   +-------------------------------------------------------------------+
   | arrow_typeof(coalesce(make_array(Int64(1)),make_array(Int64(2)))) |
   +-------------------------------------------------------------------+
   | Utf8                                                              |
   +-------------------------------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   
   ❯ select arrow_typeof(coalesce(NULL, [2]));
   +---------------------------------------------------+
   | arrow_typeof(coalesce(NULL,make_array(Int64(2)))) |
   +---------------------------------------------------+
   | Utf8                                              |
   +---------------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   
   ❯ select arrow_typeof(coalesce([1], NULL));
   +---------------------------------------------------+
   | arrow_typeof(coalesce(make_array(Int64(1)),NULL)) |
   +---------------------------------------------------+
   | Utf8                                              |
   +---------------------------------------------------+
   1 row in set. Query took 0.001 seconds.
   ```
   
   ### Expected behavior
   
   Postgres handles this correctly for example:
   ```sql
   select pg_typeof(coalesce(NULL, array[1,2,3]));
   
   -- pg_typeof
   -- integer[]
   ```
   
   ### Additional context
   
   I didn't test this extensively but I think the same is true for struct types 
(and by extension maybe all "complex" type?)
   
   If someone comes accross this, I am currently working around this by 
replacing the coalesce with a case statement:
   
   ```rust
   when(col("c1").is_null(), col("c2"))
       .otherwise(col("c1"))
       .unwrap()
       .alias("c1"),
   ```
   
   This preserves the type of the column.


-- 
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: github-unsubscr...@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to