存在这么一张表,源数据是用LZO压缩并创建了索引
drop table if exists ods_customer;
create external table ods_customer(
customer_id string,
customer_name string,
gender string,
mobile string,
birth date
)
partitioned by (dt string)
stored as
INPUTFORMAT 'com.hadoop.mapred.DeprecaatedLzoTextInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
location '/warehouse/library/ods/ods_customer';
-- 加载数据
load data inpath '/origin_data/library/data/ods_customer/2021-09-23' into table ods_customer partition(dt='2021-09-23');
-- 创建索引
hadoop jar /opt/module/hadoop-3.1.3/share/hadoop/common/hadoop-lzo-0.4.20.jar com.hadoop.compression.lzo.DistributedLzoIndexer /warehouse/library/ods/ods_customer/dt=2021-09-23;
那么以下两种查询方式得到的数据量可能是不同的
select * from ods_customer; select count(*) from ods_customer;
原因是select * from ods_customer不执行MR操作,直接采用的是customer建表语句中指定的DeprecatedLzoTextInputFormat,能够识别lzo.index为索引文件。
select count(*) from ods_customer执行MR操作,会先经过hive.input.format,其默认值为CombineHiveInputFormat,其会先将索引文件当成小文件合并,将其当做普通文件处理。更严重的是,这会导致LZO文件无法切片。
解决方法:修改默认值
hive>set hive.input.format=org.apache.hadoop.hive.ql.io.HiveInputFormat;



