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

vu8f3i0k  于 2021-05-27  发布在  Hadoop
关注(0)|答案(3)|浏览(320)

我有一个按事件日期划分的表,由于某种原因,当我将数据插入到外部表时,有些日期只有一个或两个文件,而有些日期超过200个。
在启动配置单元查询以插入数据时,我总是使用这段代码,因此我不确定它在某些日期(而不是其他日期)的哪里/如何出错。我认为“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个文件,分别。运行后的配置单元输出确认了无关文件已被删除,但当我返回并在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倍。
如果可能的话,我希望将包含许多文件的日期缩小到只有一个或两个,因为名称空间已经用完了。我对这一切都很陌生,那么有没有什么简单的方法可以将文件合并到一个单独的日期分区中呢?

ajsxfq5m

ajsxfq5m1#

通过将这一行添加到我的其他配置单元参数集之外,我能够在将零件文件插入新表时,将它们一致地合并到一个大小为5 GB或更小的文件中:

set hive.merge.smallfiles.avgsize=5000000000;

也可以使用getmerge,然后将文件放回原处,但这需要额外的步骤将文件从本地拉下来(必须有大量的存储空间,具体取决于文件的大小),这比创建新表和使用这个额外的set参数插入要麻烦得多。
另一种选择是使用

set hive.merge.mapfiles=true;

这似乎是一个参数来创建Map器的数量。如果我们有少量的文件,就必须创建那么多的Map器,这对于hadoop设计来说不是最佳的,因此tez合并选项更合适

fzwojiic

fzwojiic2#

您可以尝试设置以下属性

SET hive.merge.mapfiles=true;
SET hive.merge.mapredfiles=true;
SET hive.merge.smallfiles.avgsize=134217728; ( 128 MB)

你可以参考这个链接

bxjv4tth

bxjv4tth3#

如果hdfs/mapr fs的块大小是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.

相关问题