大資料踩過的坑 Hive insert

2021-08-15 19:27:37 字數 1584 閱讀 4007

我在對hive表資料清洗後,使用了如下sql將結果集插入到新錶中:

insert into db_name.table_name_1 (

col_1,col2,col3

)with temp_table_1 as (

select id,col_2

from db_name.table_name_2 where id = condatition

),temp_table_2 as (

select id,col_3

from db_name.table_name_3 where id = condatition

)select a.id,a.col_2,b.col_3

from temp_table_1 a

left join temp_table_2 b on a.id= b.id

出現了如下報錯資訊:

錯誤原因:

hive是支援with語法的,但是當與insert搭配使用時,語法與標準sql語法規則不一樣,需要將with放在insert之前,如下所示:

with temp_table_1 as (

select id,col_2

f rom db_name.table_name_2 where id = condatition

),temp_table_2 as (

select id,col3

from db_name.table_name_3 where id = condatition

)insert into db_name.table_name_1 (

col_1,col2,col3

)

select a.id,a.col_2,b.col_3

from temp_table_1 a

left join temp_table_2 b on a.id= b.id

但是目標表db_name.table_name_1包含col_1,col_2,col_3,col_4,col_5等多個字段。上述insert語句執行後,又報了如下錯誤:

錯誤原因:hive sql中的insert不支援插入部分字段

解決方案:將字段補全,沒有資料的字段插入空值,修改如下:

with temp_table_1 as (

select id,col_2

f rom db_name.table_name_2 where id = condatition

),temp_table_2 as (

select id,col3

from db_name.table_name_3 where id = condatition

)insert into db_name.table_name_1 (

col_1,col_2,col_3,col_4,col_5

)selecta.id,a.col_2,b.col_3,null,null

from temp_table_1 a

left join temp_table_2 b on a.id= b.id

git踩過的坑

4.git 修改當前的project的使用者名稱的命令為 git config user.name 你的目標使用者名稱 git 修改當前的project提交郵箱的命令為 git config user.email 你的目標郵箱名 如果你要修改當前全域性的使用者名稱和郵箱時,需要在上面的兩條命令中新增...

springboot踩過的坑

設定上下文路徑context path不生效 springboot 2.0之前的語法 server.context path xx 2.0之後的語法 server.servlet.context path xx 在配置yml時,報錯如下 caused by org.yaml.snakeyaml.sc...

SQL UNION踩過的坑

union 操作符用於合併兩個或多個 select 語句的結果集。請注意,union 內部的 select 語句必須擁有相同數量的列。列也必須擁有相似的資料型別。同時,每條 select 語句中的列的順序必須相同。select column name s from table name1 union...