通过追加在 Hive 中插入记录

Inserting record in Hive by appending

我正在 Hive 外部 table 上执行 INSERT 语句。我注意到对于每个新的 INSERT,都会在外部 table 引用的 HDFS 路径中创建一个新文件。我的问题是:

  1. 是否可以将新插入的数据作为追加而不是创建新文件?

  2. 我能否以某种方式控制它,使其达到一定大小,比如 1MB,只有这样 Hive 才会创建一个新文件来放置传入的插入内容?

Cloudera 说:

The INSERT INTO syntax appends data to a table. The existing data files are left as-is, and the inserted data is put into one or more new data files.

Hive 将附加 table 而不是基础文件。

您可以使用另一个 create table 强制 hive 构建 tables,并强制 reducers 为一个。这会将碎片文件复制到一个 table 中,并将它们合并到 HDFS 中的另一个位置。然后你可以交换 HDFS 中的文件。

您可以将文件放在保留区,然后在 hdfs 中检查那里的文件大小,然后将它们移到上面。然而,将文件暂时保存在本地文件系统上并移动它们似乎更容易。

要使用 hive 将文件组合成一个新文件,您可以尝试:

set hive.exec.dynamic.partition.mode=nostrict;
set hive.exec.compress.intermediate=false;
set hive.exec.compress.output=false;
set hive.exec.reducers.max=1;

create table if not exists db.table
stored as textfiel as
select * from db.othertable;

db.othertable 是具有多个碎片文件的 table。 db.table 将有一个包含组合数据的文本文件。

我知道这并不理想,更像是一种解决方法。