alamb commented on code in PR #9958:
URL: https://github.com/apache/arrow-datafusion/pull/9958#discussion_r1553464570
##########
datafusion/sqllogictest/test_files/scalar.slt:
##########
@@ -1779,6 +1779,18 @@ SELECT COALESCE(NULL, 'test')
----
test
+
+statement ok
+create table test1 as values (arrow_cast('foo', 'Dictionary(Int32, Utf8)')),
(null);
+
+
+query ?
+select coalesce(column1, 'none_set') from test1;
+----
+foo
+none_set
+
Review Comment:
Can we add a few more tests here?
1. The alternate (cast utf8 to dictionary):
```sql
select coalesce('none_set', column1) from test1;
select coalesce(NULL, 'none_set', column1) from test1;
```
3. A test on non string dictionaries, like this:
```sql
select coalesce(null, 34, arrow_cast(123, 'Dictionary(Int32, Int8)'));
select coalesce(null, arrow_cast(123, 'Dictionary(Int32, Int8)'), 34);
```
3. Also clear the table (e.g. `drop table test1`)?
##########
datafusion/expr/src/type_coercion/functions.rs:
##########
@@ -430,7 +430,7 @@ fn coerced_from<'a>(
{
Some(type_into.clone())
}
-
+ Dictionary(_, _) if matches!(type_from, Utf8) =>
Some(type_into.clone()),
Review Comment:
I think this currently says it is possible to coerce from Utf8 to any
dictionary type (e.g. even `Dictionary(Int64, Int32)`)
I think the `dictionary_coercion` function does something similar here:
https://github.com/apache/arrow-datafusion/blob/37b73751b19b82516443579c714b3b5986dac927/datafusion/expr/src/type_coercion/binary.rs#L635-L634
So maybe we need to verify we can coerce the value types, like this?
```suggestion
Dictionary(_, value_type) if coerce_from(value_type, from_type) =>
Some(type_into.clone()),
```
--
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]