首页 > 解决方案 > 将配置单元表作为单个文件输出到 HDFS

问题描述

我正在尝试将我在 hive 中的表的内容作为单个 csv 文件输出到 hdfs,但是当我运行下面的代码时,它会将其拆分为 5 个单独的文件,每个文件约为 500mb。在将结果输出为单个 csv 文件方面,我是否遗漏了什么?

set hive.execution.engine=tez;
set hive.merge.tezfiles=true;
INSERT OVERWRITE DIRECTORY  "/dl/folder_name"
row format delimited fields terminated by ','
select * from schema.mytable;

标签: hivehdfs

解决方案


在您的选择查询中添加orderby子句,然后 Hive 将强制运行single reducer,这将在 HDFS 目录中仅创建一个文件。

INSERT OVERWRITE DIRECTORY  "/dl/folder_name"
row format delimited fields terminated by ','
select * from schema.mytable order by <col_name>;

笔记:

如果输出中的行数太大,则single reducer可能需要很长时间才能完成。


推荐阅读