向hive插入数据报错

您所在的位置:网站首页 导入数据报错v21怎么办 向hive插入数据报错

向hive插入数据报错

2023-06-30 08:42| 来源: 网络整理| 查看: 265

1、问题示例

(1)hive创建表

  hive (test)> create table t1(id int,name string)   > clustered by (id) into 8 buckets   > stored as orc tblproperties ('transactionl'='true');  OK  Time taken: 13.342 seconds

(2)插入数据报错

  insert into t1 values (1,'aaa');  Query ID = grid_20211027110417_1a2f8a7b-2837-4c88-9a28-00a8b679e029  Total jobs = 2  Launching Job 1 out of 2  Number of reduce tasks determined at compile time: 8  In order to change the average load for a reducer (in bytes):   set hive.exec.reducers.bytes.per.reducer=  In order to limit the maximum number of reducers:   set hive.exec.reducers.max=  In order to set a constant number of reducers:   set mapreduce.job.reduces=  Cannot run job locally: Number of reducers (= 8) is more than 1  Starting Job = job_1635258384646_0002, Tracking URL = http://master:8088/proxy/application_1635258384646_0002/  Kill Command = /home/grid/Hadoop/hadoop-3.3.1/bin/mapred job -kill job_1635258384646_0002  Hadoop job information for Stage-1: number of mappers: 0; number of reducers: 0  2021-10-27 11:10:06,987 Stage-1 map = 0%, reduce = 0%  Ended Job = job_1635258384646_0002 with errors  Error during job, obtaining debugging information...  FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask  MapReduce Jobs Launched:   Stage-Stage-1: HDFS Read: 0 HDFS Write: 0 FAIL  Total MapReduce CPU Time Spent: 0 msec

(3)没有成功插入数据

  hive (test)> select * from t1;  OK  Time taken: 8.98 seconds

2、问题剖析

(1)从上面报错结果可知,hive成功创建了表,但却不能向表中插入数据;

(2)使用Spark-sql再次向hive创建的表插入数据,却能成功插入,但在hive中就是不行;

(3)使用hive向非桶表插入数据,是可以的;

(4)该问题,笔者已经解决,笔者曾试用过多种办法都没有解决,是在一次偶然情况解决的。由于解决过程是在反反复复测试和修改各种参数中,无意中测试成功的,反过来推测造成上述其原因如下(未进一步去检验):

A、造成上述根本原因是Hadoop主节点(master)内存不足,就是用于ResourceManager的节点,至少需要4G的运行内存,当时笔者设置Hadoop运行内存为3G。其原因是在向hive创建的桶表插入数据时,hive计算引擎设置使用mr引擎(即mapreduce)时,而使用Mapreduce时,需要4G内存才能运行。注意:非桶表或小数据,则不需要这么多内存。向桶表插入数据,那怕只是1条数据,MapReduce也都需要足够的内存。那是因为ResourceManger本身运行就占用了很大一部分内存,再执行计算任务时,就需要更多的内存。

B、Spark-sql执行桶表插入数据时,计算引擎是Spark本身,不需要额外占用过多的内存,且数据本身在内存中执行交换,所以可以执行成功,效率很高。

C、Hive使用mr作为计算引擎时,很是消耗内存,尤其是桶表。

D、因此给新手已经建议,初次配制hadoop集群时,主节点的内存一定要大一些,至少也需要4G,否则就会出现这种坑。

E、使用hive时,尽可能避免使用mr作为计算引擎,可以修改为spark或tez,可提高运行效率,但需要额外配制相关参数。

3、解决方案

(1)方案1:设置参数为:hive.exec.mode.local.auto=true

  hive (test)> set hive.exec.mode.local.auto=true;

  结果行不通,笔者已从“hive-siet.xml”配置了该参数。这是一个错误的方向,是笔者最初以为是hive参数配制不对导致的问题。

(2)方案2:

  找到Hadoop集群配制文件yarn-site.xml,设置参数:yarn.nodemanager.resource.memory-mb,参数设置示例如下:4096即为4G。

  yarn.nodemanager.resource.memory-mb   4096

另外一个与之相关的参数:yarn.scheduler.minimum-allocation-mb,笔者设置为2G,但未检验是否会影响性能。

  yarn.scheduler.minimum-allocation-mb   2048

 

 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3