一、hive 查询时发现 select * 有数据,但是 select count(*) 没有数据
select * from ods.ods_start_log limit 11;

select count(*) from ods.ods_start_log;

二、原因
建表以location的方式加载数据,此时元数据还没有记录新的数据,当执行 count(*) 时,系统会自动到元数据中读取数据,此时元数据是没有数据的。
三、解决办法
使用参数
hive.compute.query.using.stats
当hive.compute.query.using.stats=true时,select count(*) from直接从元数据保存的统计信息中获取表中记录条数。这个是默认的方式。
当hive.compute.query.using.stats=false时,该sql查询会以集群模式运行返回结果。
因此,为了真实的反应表的数据量,应该设置hive.compute.query.using.stats=false
四、结果
set hive.compute.query.using.stats=false;select count(*) from ods.ods_start_log;

在Hive查询中遇到一个现象,即使用`select *`能显示数据,但`select count(*)`却返回空结果。这可能是由于Hive在通过location方式加载数据后,元数据还未更新。解决方法是调整`hive.compute.query.using.stats`参数,将其设置为`false`,使得查询时实际扫描数据而非依赖元数据统计信息,从而得到正确的数据量。
1389

被折叠的 条评论
为什么被折叠?



