hadoop - 在 hadoop 的同一分区内合并多个文件的最佳选择?

标签 hadoop hive hdfs hiveql hadoop-partitioning

我有一个按 event_date 分区的表,由于某种原因,当我将数据插入外部表时,有些日期只有一个或两个文件,而有些则超过 200 个。

在启动 Hive 查询以插入数据时,我总是使用这段代码,所以我不确定在某些日期(但在其他日期)它在哪里/如何出现问题。我认为“merge.tezfiles”行专门处理插入时的文件合并。

SET mapred.job.queue.name=my_directory;
use this_directory;
SET hive.exec.dynamic.partition=true;
SET hive.exec.dynamic.partition.mode=nonstrict;
SET hive.exec.max.dynamic.partitions=2000;
SET hive.exec.max.dynamic.partitions.pernode=2000;
SET hive.merge.tezfiles=true;

我在网上找到的所有内容都提到必须将文件复制到本地并再次上传。

有没有办法以干净简单的方式合并每个日期分区中的多个文件?

我在几个日期分别尝试了 4 个和 15 个文件。运行后的 Hive 输出确认无关文件已被删除,但当我返回查看 Hadoop 时,发现与开始时一样多。幸好我查的时候数据还是准确的,所以我不确定它到底删除了什么?这根本不是正确的命令吗?

alter table table_being_edited PARTITION(event_dt='2017-01-01') CONCATENATE;  

这是确认额外文件已被删除的一行:

Moved: 'my_hdfs_filepath/event_dt=2019-10-24/000052_0' to trash at: my_trash_directory/.Trash/Current

好的 耗时:75.321秒

对于有 15 个文件的日期,它给了我类似的输出 15 倍。

我希望尽可能将许多文件的日期缩小到一两个,因为我们的命名空间快用完了。我对所有这一切都很陌生,所以有没有准系统,在单个日期分区内合并文件的简单方法?

最佳答案

如果你的HDFS/MapR-FS block size是256MB,smallfiles.avgsize最好设置为256MB

SET hive.merge.tezfiles=true; --Merge small files at the end of a Tez DAG.
SET hive.merge.mapfiles=true; --Hive will start an additional map-reduce job to merge the output files into bigger files
SET hive.merge.mapredfiles=true; --Hive will start an additional map-reduce job to merge the output files into bigger files
SET hive.merge.orcfile.stripe.level=true; --When hive.merge.mapfiles, hive.merge.mapredfiles or hive.merge.tezfiles is enabled while writing a table with ORC file format, enabling this configuration property will do stripe-level fast merge for small ORC files.
SET hive.merge.size.per.task=256000000; --Size of merged files at the end of the job.
SET hive.merge.smallfiles.avgsize=256000000; --When the average output file size of a job is less than this number, Hive will start an additional map-reduce job to merge the output files into bigger files. This is only done for map-only jobs if hive.merge.mapfiles is true, and for map-reduce jobs if hive.merge.mapredfiles is true.

关于hadoop - 在 hadoop 的同一分区内合并多个文件的最佳选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58809968/

相关文章:

hadoop - Hadoop Tasklog问题

sql - 如何删除空字符串

shell - 我可以使用-put命令在HDFS中传输文件吗?

docker - 色相-Docker产生无法连接的错误

hadoop - Hadoop应用程序中Avro的用例

hadoop - HDFS 加密 |远程异常

hadoop - Cloudera hadoop : not able to run Hadoop fs command and at same time HBase is not able to create directory on HDFS?

sql - 配置单元:无法从配置单元表中的文件插入数组和映射

java - 使用 Java 读取远程 HDFS 文件

hadoop - Hive 命令执行 NOT IN 子句