记录一个Hive的一个报错

记录一个Hive的一个报错,第1张

记录一个Hive的一个报错 报错日志

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.StatsTask

报错场景
Hive版本:3.0
执行引擎:MapReduce

往表中进行insert into *** 作,出现报错,具体情况往下看

开始验证 1 准备好 2 张表

student1,student2

1) 建表
CREATE TABLE student1 (
    name     string comment '姓名',
    age      int    comment '年龄',
    score    double comment '分数'
)
COMMENT '学生表'
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
;

-- 创建表student2,结构和student1保持一致
create table student2 like student1;
2) 准备数据

张三 18 69
李四 28 88.5
网二 23 87

往表student1中加载原始数据

LOAD DATA LOCAL INPATH '/data/shell/student.txt' INTO TABLE student1;

查看表student结果

select * from student1;
结果:
张三 18 69
李四 28 88.5
网二 23 87

数据正常

3) 往表student2中插入数据
-- 1、into方式插入数据
insert into table student2
select name,age,score from student1;

第一次insert into 正常执行且查询结果无误

-- 2、再次往表student2中插入数据
insert into table student2
select name,age,score from student1;

第二次insert into 执行快结束的时候出现了报错,报错结果为下面所示

# 如黄色部分所示
Loading data to table default.student2
`FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.StatsTask`
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 1  Reduce: 1   Cumulative CPU: 4.73 sec   HDFS Read: 15711 HDFS Write: 353 SUCCESS

查询表中数据得到

hive> select * from student2;
OK
张三	18	69.0
李四	28	88.5
网二	23	87.0
张三	18	69.0
李四	28	88.5
网二	23	87.0

再次以insert into 方式插入依旧报错,此处略去…

-- 3、以insert overwrite方式插入
insert overwrite table student2
select name,age,score from student1;

如果再insert overwrite方式插入,则正常执行,并且覆盖了原有的数据,并且数据正常。

-- 4、再次insert into 方式插入数据
insert into table student2
select name,age,score from student1;

很奇怪的发现发现还是同样的报错,并且找不到解决的方法,头疼…

-- 5、把表先truncate,再插入
truncate table student2;
-- 5.1 truncate之后第一次 into 插入数据
insert into table student2
select name,age,score from student1;

truncate之后第一次插入正常,没有报错,数据结果也是OK的,以为和表中没数据了有关系,继续测试

-- 5.2 truncate之后第二次 into 插入数据
insert into table student2
select name,age,score from student1;

此时应该很惊讶的,这次的insert into也没有报错,这是why? 难道和truncate *** 作有关?
接着继续测试…

4) 往表student3中插入数据

准备好表student3 表结构和student1保持一致
这一次,我在建好表之后不做任何 *** 作,进行truncate *** 作

create table studnet3 like student1;
truncate table student3;
-- 1.第一次往表student3中以insert into方式插入数据
insert into table student3
select name,age,score from student1;

没有意外的会发现,第一次正常执行,并且表student3中数据正常。

-- 2.第二次以insert into 方式插入数据
insert into table student3
select name,age,score from student1;

喔喔喔…
天哪,居然没有报错的执行成功了,并且表中数据也是正常的,这是为啥呢?

查了有关资料,不知道具体原因是什么,有知道的小伙伴可以留言我,帮我解答一下困惑,谢谢!!!

如果以后有遇到这种报错的,可以把表先truncate一下试试看。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5677211.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存