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

查看:3261
本文介绍了将数据从.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;

我可以运行一个 SELECT * FROM test_details_txt; 在Hive的表中。

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:格式错误的ORC文件hdfs:// master:6000 / user / hive / warehouse / test.db / transaction_details / test_details.txt。无效的postscript。

使用上述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 数据文件。

因此,在这种情况下,输入文件 /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.

下面是一个例子:

Here is an example:

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天全站免登陆