将数据从 .txt 文件加载到在 Hive 中存储为 ORC 的表 [英] Loading Data from a .txt file to Table Stored as ORC in Hive

查看:42
本文介绍了将数据从 .txt 文件加载到在 Hive 中存储为 ORC 的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .txt 格式的数据文件.我正在使用该文件将数据加载到 Hive 表中.当我将文件加载到

I have a data file which is in .txt format. I am using the file to load data into Hive tables. When I load the file in a table like

CREATE TABLE test_details_txt(
visit_id INT,
store_id SMALLINT) STORED AS TEXTFILE;

使用

LOAD DATA LOCAL INPATH '/home/user/test_details.txt' INTO TABLE test_details_txt;

并且我可以在 Hive 中的表上运行 SELECT * FROM test_details_txt;.

and I can run a SELECT * FROM test_details_txt; on the table in Hive.

但是,如果我尝试将数据加载到

However If I try to load the data in a table that is

CREATE TABLE test_details_txt(
visit_id INT,
store_id SMALLINT) STORED AS ORC; 

我在尝试运行 SELECT 时收到以下错误:

I receive the following error on trying to run a SELECT:

因异常 java.io.IOException:java.io.IOException: Malformed ORC file hdfs://master:6000/user/hive/warehouse/test.db/transaction_details/test_details.txt 而失败.无效的附言.

使用上述 LOAD 语句加载数据时,我没有收到任何错误或异常.

While loading the data using above LOAD statement I do not receive any error or exception.

在使用 LOAD DATA IN PATH.. 命令将数据存储到 ORC 表中时,是否还有需要做的事情?

Is there anything else that needs to be done while using the LOAD DATA IN PATH.. command to store data into an ORC table?

推荐答案

LOAD DATA 只是将文件复制到 hive 数据文件.Hive 在将数据加载到表中时不做任何转换.

LOAD DATA just copies the files to hive datafiles. Hive does not do any transformation while loading data into tables.

因此,在这种情况下,如果您要将输入文件 /home/user/test_details.txt 加载到 ORC 表中,则它需要采用 ORC 格式.

So, in this case the input file /home/user/test_details.txt needs to be in ORC format if you are loading it into an ORC table.

一种可能的解决方法是创建一个带有 STORED AS TEXT 的临时表,然后将 LOAD DATA 放入其中,然后将该表中的数据复制到 ORC 表中.

A possible workaround is to create a temporary table with STORED AS TEXT, then LOAD DATA into it, and then copy data from this table to the ORC table.

这是一个例子:

CREATE TABLE test_details_txt( visit_id INT, store_id SMALLINT) STORED AS TEXTFILE;
CREATE TABLE test_details_orc( visit_id INT, store_id SMALLINT) STORED AS ORC;

-- Load into Text table
LOAD DATA LOCAL INPATH '/home/user/test_details.txt' INTO TABLE test_details_txt;

-- Copy to ORC table
INSERT INTO TABLE test_details_orc SELECT * FROM test_details_txt;

这篇关于将数据从 .txt 文件加载到在 Hive 中存储为 ORC 的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆