如何将文本文件加载到存储为序列文件的Hive表中

cld*_*ldo 26 hadoop hive

我有一个hive表存储为序列文件.

我需要将一个文本文件加载到此表中.如何将数据加载到此表中?

lib*_*ack 52

您可以将文本文件加载到文本文件Hive表中,然后将此表中的数据插入到序列文件中.

从制表符分隔文件开始:

% cat /tmp/input.txt
a       b
a2      b2
Run Code Online (Sandbox Code Playgroud)

创建一个序列文件

hive> create table test_sq(k string, v string) stored as sequencefile;
Run Code Online (Sandbox Code Playgroud)

尝试加载; 正如预期的那样,这将失败:

hive> load data local inpath '/tmp/input.txt' into table test_sq;
Run Code Online (Sandbox Code Playgroud)

但是用这张桌子:

hive> create table test_t(k string, v string) row format delimited fields terminated by '\t' stored as textfile;
Run Code Online (Sandbox Code Playgroud)

负载工作得很好:

hive> load data local inpath '/tmp/input.txt' into table test_t;
OK
hive> select * from test_t;
OK
a       b
a2      b2
Run Code Online (Sandbox Code Playgroud)

现在从文本表加载到序列表中:

insert into table test_sq select * from test_t;
Run Code Online (Sandbox Code Playgroud)

也可以使用覆盖来加载/插入以替换所有.

  • 可以直接完成,我们可以从TSV文件加载到序列格式表的东西,而无需中间保存到其他表吗? (2认同)