Hive那些事儿之八-大数据踩过的坑——Hive insert

在进行Hive数据清洗并尝试使用INSERT语句将结果集存入新表时遇到错误。首先,解析错误提示发现Hive的WITH子句必须放在INSERT之前。修正后,因尝试只插入部分字段导致NullPointerException。解决方案是完整指定所有字段,并为未提供数据的字段插入NULL值。
摘要由CSDN通过智能技术生成

Hive那些事儿之八-大数据踩过的坑——Hive insert

我在对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

出现了如下报错信息:

Error while compiling statement: FAILED: ParseException line 15:0 cannot recognize input near ‘with’ ‘temp_table_1’ ‘as’ in statement
错误原因:

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 (
  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值