Hive常见问题

1.内存溢出

(1)map阶段

解决:一般存在MapJoin,设置参数set hive.auto.convert.join = false转成reduce端的Common Join。

(2)shuffle阶段

解决:减少每个reduce处理的数据量,调整参数:hive.exec.reducers.bytes.per.reducer,默认300000000。或调整放在内存里的最大片段所占百分比(set mapreduce.reduce.shuffle.memory.limit.percent=0.10)。

(3)reduce阶段

解决:减少每个reduce处理的数据量,调整参数:hive.exec.reducers.bytes.per.reducer,默认300000000。如果存在数据倾斜,单纯增加reduce个数没有用,参考“Hive优化方法.ppt”进行数据倾斜优化。

 

2.执行动态分区HQL报错,报错信息类似如下:

org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error: Unable to deserialize reduce input key from x1x128x0x0x19x1x255 with properties {columns=reducesinkkey0,reducesinkkey1,reducesinkkey2,reducesinkkey3, serialization.lib=org.apache.hadoop.hive.serde2.binarysortable.BinarySortableSerDe, serialization.sort.order=++++++, columns.types=int,int,int,int,string,bigint}

解决:设置参数set hive.optimize.sort.dynamic.partition=false。

 

3.Hive创建文件数过多问题,报错信息类似如下:

total number of created files now is 100130, which exceeds 100000. Killing the job

解决:调大参数hive.exec.max.created.files。

 

4.Hive使用过多的变量替换,报错信息如下:

FAILED: IllegalStateException Variable substitution depth too large: 40

解决:调大参数hive.variable.substitute.depth。

 

5.select * 使用MR而不使用fetchtask

解决:set hive.fetch.task.conversion=minimal。

 

6.分区表分区字段是日期类型时限制分区条件使用to_unix_timestamp方法,如果使用unix_timestamp方法仍会扫全表。

 

Causedby:org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hdfs.protocol.FSLimitException$PathComponentTooLongException): The maximum path component name limit of  ...Could not find status of job:job_id...这个问题是job name过长导致,一般任务运行成功,但看不到日志,historyserver提示任务not found。

解决:设置job 的名称set mapreduce.job.name=XXX;

 

7.使用动态分区时碰到如下报错信息:

Failed with exception Number of dynamic partitions created is 1191, which is more than 1000. To solve this try to set hive.exec.max.dynamic.partitions to at least 1191

参数hive.exec.max.dynamic.partitions限制了所允许的最大分区个数,默认值是1000。

解决:调大参数hive.exec.max.dynamic.partitions。

 

8.rcfile格式的表insert数据时报错:

 

“Caused by: java.lang.UnsupportedOperationException: Currently the writer can only accept BytesRefArrayWritable”

       解决:修改rcfile 表 serde 属性

       alter table table_name set serde 'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe';

 

9.任务执行报“Caused by: java.io.IOException: Split metadata size exceeded 10000000. Aborting job XXX”job.splitmetainfo文件大小超过默认值10000000(10M)。

       解决:调大参数mapreduce.jobtracker.split.metainfo.maxsize。

 

10.Hive执行报“FAILED: ParseException line ”

       解决:Hive语法问题,请检查自己的语句,如有不确定请查阅Hive语法。

 

11.Hive任务执行过程中失败,报“Caused by: java.io.FileNotFoundException: File does not exist: XXX”

       原因:任务运行过程中依赖的表发生了变化,可能是表被删了、表重建了或者表数据重新生成之类的等等情况。譬如,报错:“Caused by: java.io.FileNotFoundException: File does not exist: hdfs://XXX/user/A/hive/warehouse/A.db/trec_season2_coupon_info_pc/000000_0”,则是因为任务运行过程中,依赖的表A.trec_season2_coupon_info_pc发生了变化。

 

12.对于Hive里的分区表,新增字段后,通过insert overwrite等方式重新生成历史分区的数据,发现新增字段仍旧是null值。

        解决:Hive分区表新增字段后,需要对历史老分区进行重建才能查询新增字段,但是对于新增字段后新生成的分区是不受影响的,能正常查询数据。

 

FAILED: RuntimeException MetaException(message:java.lang.ClassNotFoundException Class org.openx.data.jsonserde.JsonSerDe not found)

        解决:确认是否对json-serde.jar执行了add jar。

 

13.FAILED: SemanticException [Error 10087]: The same output cannot be present multiple times

        原因:使用多重insert(multi insert)时,结果是非分区表则不能是同一个,分区表必须是不同分区,结果是hdfs目录的也必须不同。

 

14.任务运行正常,在最后move数据阶段报错:Failed with exception Unable to move source XXX to destination XXX  FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask

        解决:set hive.exec.copyfile.maxsize=10000000000;

 

15.FAILED: SemanticException Line 0:-1 Invalid column reference '$f1’

解决:set hive.cbo.enable=false;

 

16.重复列名,报错关键字Ambiguous column reference * in * .

       解决:去掉重复的字段

       示例:select t.id from (select dummy,dummy from default.dual)t;

                  FAILED: SemanticException [Error 10007]: Ambiguous column reference dummy in t

                  去掉子查询里的一个dummy字段。

 

17.union all的子句里不支持orderByClause、clusterByClause、distributeByClause、sortByClause或limitClause

        解决:改造hql,去掉union all子查询里的orderByClause、clusterByClause、distributeByClause、sortByClause和limitClause语句

        示例:select t.id from (select dummy from default.dual limit 1 union all select dummy from default.dual limit 1)t;

          去掉两个子查询里的limit 1;

 

18.建表列名不允许包含.或:,报错如下:ParseException line 1:45 Failed to recognize predicate ‘)’. Failed rule: ‘[., :] can not be used in column name in create table statement.’ in column specification

       解决:检查建表语句,将字段名中包含的.或: 去掉。

 

19.Cannot modify hive.conf.restricted.list at runtime. It is in the listof parameters that can’t be modified at runtime

       原因:对hive.exec.max.dynamic.partitions,hive.exec.max.dynamic.partitions.pernode,hive.exec.max.created.files三个参数值进行了限制,用户自定义设置不生效,不影响任务的执行,除非动态创建的分区数和任务创建的文件数在任务运行过程中超过了限制值,任务才会失败。

 

20.interval 是hive-1.2版本里新增的关键字,不可作为表字段名、别名。

示例1:select dummy as interval from dual;  查询报错

NoViableAltException(142@[134:7: ( ( ( KW_AS )? identifier ) | ( KW_AS LPAREN identifier ( COMMA identifier )* RPAREN ) )?])

FAILED: ParseException line 1:16 cannot recognize input near 'as' 'interval' 'from' in selection target

示例2:create table test_interval(interval string);

NoViableAltException(142@[])

at org.apache.hadoop.hive.ql.parse.HiveParser_IdentifiersParser.identifier(HiveParser_IdentifiersParser.java:10858)

FAILED: ParseException line 1:27 cannot recognize input near 'interval' 'string' ')'

 

posted @ 2022-10-27 22:28  业余砖家  阅读(1438)  评论(0)    收藏  举报