apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
6.33k stars 1.2k forks source link

Coerce Array inner types #13452

Closed blaginin closed 1 day ago

blaginin commented 5 days ago

Which issue does this PR close?

Closes #12291

Rationale for this change

Currently, we don't attempt to coerce inner list types, and so this works (although it shouldn't)

SELECT make_array(2) x UNION ALL SELECT make_array(now()) x;

What changes are included in this PR?

Now we’ll try to coerce inner types instead of just using the type of the first array.

Are these changes tested?

Yes, added a test

Are there any user-facing changes?

No

blaginin commented 5 days ago

That was a very fast review 😅🙏

jayzhan211 commented 4 days ago
query error DataFusion error: type_coercion\ncaused by\nError during planning: Incompatible inputs for Union: Previous inputs were of type List(.*), but got incompatible type List(.*) on column 'x'
SELECT make_array(2) x UNION ALL SELECT make_array(now()) x;

query ?
select make_array(arrow_cast(2, 'UInt8')) x UNION ALL SELECT make_array(arrow_cast(-2, 'Int8')) x;
----
[-2]
[2]

The queries has nothing to do with the list coercion. I checked the query and it already works correctly in main branch.

alamb commented 1 day ago

@jayzhan211 are you good to merge this PR?

jayzhan211 commented 1 day ago

Thanks @blaginin @alamb @findepi