在hive(hadoop)中添加文件后,它在仓库中不可见?

时间:2014-08-20 14:56:25

标签: hadoop hive

我可以在hive中添加一个文件,如:

hive> add file /home/vis/Documents/def.txt;

hive>list files;
/home/vis/Documents/def.txt

现在问题是,上面的文件在我的仓库中不可见。

是否可以在配置单元仓库(/user/hive/warehouse)中看到它。

如果没有,那么如何在配置单元中看到该文件?

1 个答案:

答案 0 :(得分:1)

Hive add command puts the file in distributed cache。这是 mapred.local.dir 。分布式缓存旨在分发需要存在于所有节点上以供MR作业使用的文件,在本例中为您的Hive查询。

Cloudera有a document that gives examples。 根据您的目标,您可能希望先将数据加载到hdfs,然后再加载create an external table

CREATE EXTERNAL TABLE page_view(viewTime INT, userid BIGINT,
     page_url STRING, referrer_url STRING,
     ip STRING COMMENT 'IP Address of the User',
     country STRING COMMENT 'country of origination')
 COMMENT 'This is the staging page view table'
 ROW FORMAT DELIMITED FIELDS TERMINATED BY '\054'
 STORED AS TEXTFILE
 LOCATION '<hdfs_location>';

如果您的意图是将数据文件作为仓库的一部分,则可以省略 external 关键字。

CREATE TABLE page_view(viewTime INT, userid BIGINT,
    page_url STRING, referrer_url STRING,
    ip STRING COMMENT 'IP Address of the User')
COMMENT 'This is the page view table'
PARTITIONED BY(dt STRING, country STRING)
STORED AS SEQUENCEFILE;