hive 小文件分析

1、获取fsimage文件:

hdfs dfsadmin -fetchImage /data/xy/

2、从二进制文件解析:

hdfs oiv -i /data/xy/fsimage_0000000019891608958 -t /data/xy/tmpdir -o /data/xy/out -p Delimited -delimiter ","

3、创建hive表

create database if not exists hdfsinfo;

use hdfsinfo;

CREATE TABLE fsimage_info_csv(

path string,

replication int,

modificationtime string,

accesstime string,

preferredblocksize bigint,

blockscount int,

filesize bigint,

nsquota string,

dsquota string,

permission string,

username string,

groupname string)

ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'

WITH SERDEPROPERTIES ('field.delim'=',', 'serialization.format'=',')

STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat';

4、存储HDFS元数据加载进hive中

hdfs dfs -put /data/xy/out /user/hive/warehouse/hdfsinfo.db/fsimage_info_csv/

hdfs dfs -ls /user/hive/warehouse/hdfsinfo.db/fsimage_info_csv/

Hive: MSCK REPAIR TABLE hdfsinfo.fsimage_info_csv;

select * from hdfsinfo.fsimage_info_csv limit 5;

5、统计叶子目录下小文件数据量(4194304 H字节,即<4M)

SELECT

dir_path ,

COUNT(*) AS small_file_num,

modificationtime,

accesstime

FROM

( SELECT

modificationtime,

accesstime,

relative_size,

dir_path

FROM

(

SELECT

(CASE filesize < 4194304 WHEN TRUE THEN 'small' ELSE 'large' END) AS relative_size,

modificationtime,

accesstime,

split(

substr(

concat_ws('/', split(PATH, '/')),

1,

length(concat_ws('/', split(PATH, '/'))) - length(last_element) - 1

),

',')0 as dir_path

FROM (

SELECT

modificationtime,

accesstime,

filesize,

PATH,

split(PATH, '/')size(split(PATH, '/')) - 1 as last_element

FROM hdfsinfo.fsimage_info_csv

) t0 ) t1

WHERE

relative_size='small') t2

GROUP BY

dir_path,modificationtime,accesstime

ORDER BY

small_file_num desc

limit 500;

5、统计叶子目录下小文件数据量(4194304 H字节,即<4M)

SELECT

dir_path,

COUNT(*) AS small_file_num

FROM

( SELECT

relative_size,

dir_path

FROM

(

SELECT

(CASE filesize < 41943040 WHEN TRUE THEN 'small' ELSE 'large' END) AS relative_size,

split(

substr(

concat_ws('/', split(PATH, '/')),

1,

length(concat_ws('/', split(PATH, '/'))) - length(last_element) - 1

),

',')0 as dir_path

FROM (

SELECT

filesize,

PATH,

split(PATH, '/')size(split(PATH, '/')) - 1 as last_element

FROM hdfsinfo.fsimage_info_csv

WHERE

permission not LIKE 'd%'

) t0 ) t1

WHERE

relative_size='small') t2

GROUP BY

dir_path

ORDER BY

small_file_num desc

limit 50000;

相关推荐
RestCloud5 小时前
目标端已有数据处理,覆盖/合并/跳过三种策略选择
服务器·数据库·数据仓库·etl·etlcloud·数据传输·数据集成平台
Francek Chen6 小时前
【大数据处理与分析】Spark:03 Spark运行架构
大数据·hadoop·分布式·架构·spark
技术小泽1 天前
数开精讲chapter03:分析型引擎ClickHouse与Doris-StarRocks写入机制
数据仓库·后端·clickhouse·数据分析·infra
Nefu_lyh1 天前
【Hadoop】02 详解HDFS中NameNode的工作机制与元数据管理
大数据·hadoop·hdfs
SeanQhl2 天前
Hadoop 单节点调优
hadoop·hdfs·性能调优·yarn·毕昇jdk
看浪的路人2 天前
第9讲:数据管道 Agent——从「ETL 脚本」到「自动化数据工厂」
数据仓库·自动化·etl
隔窗听雨眠2 天前
智能问数究竟替代了BI的哪一层
数据仓库·chatbi·商业智能
学编程就要猛3 天前
ETL(Extract Transform Load)
数据仓库·etl
衡石科技6 天前
二十多种数据源接进来:适配层、方言重写与 ETL 管道工程
数据仓库·etl·数据集成
skywalk81637 天前
lightharness第一次大规模开hive任务卡成功
人工智能·hive·agent·deepseek·lightharness