Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNION schema depends on branch order in case of array values #12292

Open
findepi opened this issue Sep 2, 2024 · 4 comments
Open

UNION schema depends on branch order in case of array values #12292

findepi opened this issue Sep 2, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@findepi
Copy link
Member

findepi commented Sep 2, 2024

Describe the bug

> SELECT DISTINCT arrow_typeof(x[0]) FROM (SELECT make_array(2) x UNION ALL SELECT make_array(now()) x);
+---------------------------+
| arrow_typeof(x[Int64(0)]) |
+---------------------------+
| Int64                     |
+---------------------------+

but same query with union branches swapped gives different return type

> SELECT DISTINCT arrow_typeof(x[0]) FROM (SELECT make_array(now()) x UNION ALL SELECT make_array(2) x);
+---------------------------------------+
| arrow_typeof(x[Int64(0)])             |
+---------------------------------------+
| Timestamp(Nanosecond, Some("+00:00")) |
+---------------------------------------+

To Reproduce

SELECT DISTINCT arrow_typeof(x[0]) FROM (SELECT make_array(2) x UNION ALL SELECT make_array(now()) x);
SELECT DISTINCT arrow_typeof(x[0]) FROM (SELECT make_array(now()) x UNION ALL SELECT make_array(2) x);

Expected behavior

The schema (output type) of UNION ALL should not depend on syntactic order of union's branches.

Additional context

No response

@findepi findepi added the bug Something isn't working label Sep 2, 2024
@findepi
Copy link
Member Author

findepi commented Sep 2, 2024

So far i did not reproduce the problem for queries without arrays, so it might be array specific and thus related to #12291.

@jayzhan211
Copy link
Contributor

jayzhan211 commented Sep 2, 2024

We should return error since integer is not able to cast to timestamp and vice versa

D SELECT DISTINCT x[0] FROM (SELECT [now()] x UNION ALL SELECT [2] x);
Conversion Error: Unimplemented type for cast (INTEGER -> TIMESTAMP WITH TIME ZONE)
LINE 1: ...OM (SELECT [now()] x UNION ALL SELECT [2] x);

@findepi
Copy link
Member Author

findepi commented Sep 3, 2024

@jayzhan211 agree with you. I created #12291 for this separately.
Once this is solved, do you think there won't be any latent case where UNION schema depends on branch syntactical order?

@jayzhan211
Copy link
Contributor

@jayzhan211 agree with you. I created #12291 for this separately. Once this is solved, do you think there won't be any latent case where UNION schema depends on branch syntactical order?

I guess we would need type_union_resolution for Union somewhere 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants