You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
You can union columns with different types. And it crashes if we order by this column
To Reproduce
it is just strange behavior: select 1 a union all select 'a';
+---+
| a |
+---+
| 1 |
| a |
+---+
it should work, however since 1 is an integer and 1.1 is a decimal, it crashes: select 1 a union all select 1.1 order by 1;
Additional context
Physical Sort Node does concat and it crashes. Looks like Union node has to autocast numeric types and returns error for rest types;
@alamb I am going to fix this problem. Is it fine if I will implement autocast for numeric types in UnionExec? Or you see better way?
I think the appropriate code to call would be "coerce" (as in the types of the union should be coerced to a common type). There is already code to do that for other similar operations (like InList, etc)
@gandronchik
This is an error in the data type or type coercion which is not supported in the union.
You can follow the inlist or the binary type coercion do this in the union, we can help you to review the pr.
But now we are doing the migration the type coercion to logical phase #3388
Activity
gandronchik commentedon Sep 13, 2022
@alamb I am going to fix this problem. Is it fine if I will implement autocast for numeric types in UnionExec? Or you see better way?
alamb commentedon Sep 13, 2022
I think the appropriate code to call would be "coerce" (as in the types of the union should be coerced to a common type). There is already code to do that for other similar operations (like
InList, etc)liukun4515 commentedon Sep 14, 2022
@gandronchik
This is an error in the data type or type coercion which is not supported in the union.
You can follow the inlist or the binary type coercion do this in the union, we can help you to review the pr.
But now we are doing the migration the type coercion to logical phase #3388
gandronchik commentedon Sep 14, 2022
@liukun4515 Got it. I will implement it in logical plan then
liukun4515 commentedon Sep 14, 2022
you can refer this pr #3472
gandronchik commentedon Sep 16, 2022
Why did you decide to do coercion in optimizators? At least in case with union I think it is better to do it directly in union building function
ovr commentedon Sep 16, 2022
I highly agree with @gandronchik that this should be done in the planner instead of the type coerce optimizer.
liukun4515 commentedon Sep 17, 2022
Yes, agree with you.
The type coercion should be done in the analyse phase, because of the codebase we can do this in the right place.
We do the type coercion in the physical phase when creating the physical expr.
cc @alamb @andygrove