錯誤碼:ODPS-0130241: Illegal union operation
錯誤1:Illegal union operation - type mismatch for column xx of UNION, left is YY while right is ZZ
錯誤資訊樣本
ODPS-0130241:[m,n] Illegal union operation - type mismatch for column xx of UNION, left is YY while right is ZZ
問題描述
兩個表進行union操作的時候,要求這兩個表的資料類型必須匹配,否則會報錯。
解決方案
修改query,必要時可以執行顯式類型轉換,以保證union兩邊資料的類型相匹配。
Query樣本
--建立表
odps> create table mc_test1
(
a string
);
odps> create table mc_test2
(
a bigint
);
--錯誤,union兩邊的資料類型不匹配
odps> (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
--正確,使用顯式類型轉換以保證union兩邊的資料類型一致:
odps> (select a
from mc_test1)
union all
(select cast(a as string)
from mc_test2);