踩坑实录Hive中select * 没有数据,而select count(*)有数据

目录

背景

问题定位

原因1.压缩导致

解决方案

原因2.分区文件location不一致导致

解决方案

原因3.元数据未更新

解决方案


背景

hdfs文件有数据,Hive中select * 没有数据,而select count(*)有数据

问题定位

原因1.压缩导致

表结构未压缩,数据压缩了,select查询与表结构有关系

解决方案

使用select时指定与数据一致的压缩方法就可以查询出来压缩过的收据了

SET hive.exec.compress.output=true;

SET mapred.output.compression.codec=com.hadoop.compression.lzo.LzopCodec;

原因2.分区文件location不一致导致

hdfs迁移到jfs过程中导致部分分区在hdfs,部分分区在jfs

解决方案

需要每个分区单独去修改元数据

update SDS set LOCATION='jfs://hd01-jfs/apps/hive/warehouse/db_name.db/table_name/ds=2022-05-27' ;

批量生成所有分区修改语句

select a.SD_ID, a.PART_NAME,b.`LOCATION` ,concat('update SDS set LOCATION=',"'",'jfs://hd01-jfs/apps/hive/warehouse/db_name.db/table_name/',a.PART_NAME,"'",' where SD_ID=',a.SD_ID)

from partitions a

left join sds b

on a.SD_ID=b.SD_ID

where a.TBL_ID='502002'

原因3.元数据未更新

建表以location的方式加载数据,元数据没有记录新的数据,当执行 count(*) 时,系统会自动到元数据中读取数据,此时元数据是没有数据的。

解决方案

set hive.compute.query.using.stats=true;

当hive.compute.query.using.stats=true时,select count(*) from直接从元数据保存的统计信息中获取表中记录条数。这个是默认的方式。
当hive.compute.query.using.stats=false时,该sql查询会以集群模式运行返回结果。
因此,为了真实的反应表的数据量,应该设置hive.compute.query.using.stats=false

未经允许不得转载:木盒主机 » 踩坑实录Hive中select * 没有数据,而select count(*)有数据

赞 (0)

相关推荐

    暂无内容!