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;

相关推荐
B站计算机毕业设计超人9 小时前
计算机毕业设计hadoop+spark股票基金推荐系统 股票基金预测系统 股票基金可视化系统 股票基金数据分析 股票基金大数据 股票基金爬虫
大数据·hadoop·python·spark·课程设计·数据可视化·推荐算法
viperrrrrrrrrr717 小时前
大数据学习(36)- Hive和YARN
大数据·hive·学习
重生之Java再爱我一次20 小时前
Hive部署
数据仓库·hive·hadoop
想做富婆21 小时前
大数据,Hadoop,HDFS的简单介绍
大数据·hadoop·分布式
WorkAgent1 天前
windows下本地部署安装hadoop+scala+spark-【不需要虚拟机】
hadoop·spark·scala
JZC_xiaozhong1 天前
低空经济中的数据孤岛难题,KPaaS如何破局?
大数据·运维·数据仓库·安全·ci/cd·数据分析·数据库管理员
村口蹲点的阿三1 天前
Spark SQL 中对 Map 类型的操作函数
javascript·数据库·hive·sql·spark
重生之Java再爱我一次1 天前
Hadoop集群搭建
大数据·hadoop·分布式
中东大鹅1 天前
MongoDB的索引与聚合
数据库·hadoop·分布式·mongodb