Error code: ODPS-0130241: Illegal union operation
Error Message 1: Illegal union operation - type mismatch for column xx of UNION, left is YY while right is ZZ
Sample
ODPS-0130241:[m,n] Illegal union operation - type mismatch for column xx of UNION, left is YY while right is ZZ
Description
When you perform a union operation on two tables, the data types of the two tables must match. Otherwise, an error is returned.
Solution
Modify the query statement and perform explicit data type conversions if necessary. This ensures that the data types of the tables on which the union operation is performed match.
Query examples
-- Create a table.
create table mc_test1
(
a string
);
odps> create table mc_test2
(
a bigint
);
-- Incorrect usage. The data types of the tables on which the union operations is performed do not match.
(select a
from mc_test1)
union all
(select a
from mc_test2);
FAILED: ODPS-0130241:[4,9] Illegal union operation - type mismatch for column 0 of UNION, left is STRING while right is BIGINT
-- Correct usage. An explicit data type conversion is used to ensure that the data types of the tables on which the union operation is performed match.
(select a
from mc_test1)
union all
(select cast(a as string)
from mc_test2);