hadoop - Hive 托管表与外部表 : LOCATION directory

标签 hadoop hive

我一直在阅读一些 HIVE 书籍和教程。其中一本书 - Hadoop in Practice 说

When you create an external (unmanaged) table, Hive keeps the data in the directory specified by the LOCATION keyword intact. But if you were to execute the same CREATE command and drop the EXTERNAL keyword, the table would be a managed table, and Hive would move the contents of the LOCATION directory into /user/hive/ warehouse/stocks, which may not be the behavior you expect.

我使用 LOCATION 关键字创建了一个托管表。然后将数据从 HDFS 文件加载到表中。但是我看不到在/user/hive/warehouse 下创建的任何目录。相反,新目录是在提到的 LOCATION 中创建的。所以我认为如果我创建一个提到 LOCATION 的 MANAGED 表,那么 Hive 仓库目录中没有创建任何内容?这种理解是否正确?

此外,如果在 LOAD 命令期间输入文件的位置是 hdfs,则内部表或外部表都会将数据移动到它们的位置。这种理解也是正确的吗?

最佳答案

首先当你创建一个managed tablelocation关键字,它不会在指定的 location 处创建目录,它会给你一个异常(exception):FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:hdfs://path/of/the/given/location is not a directory or unable to create one) .
这意味着在 DDL 中,location你给的,首先需要目录存在,否则上面给定的异常将被抛出。
接下来,您可以使用 location 创建 DDL给出。
接下来你可以使用 select * from <table>命令查看数据(无需加载数据)。
但是,当您删除此表时,您的数据也会从 hdfs 中消失(与外部表不同)并且元数据也会消失。
这是托管表与 location 之间的主要区别。关键词。它的行为部分类似于外部表,部分类似于托管表。
外部,例如,您不必加载数据,只需指定位置即可。
托管,就像你删除表一样,数据也被删除。
希望这是有道理的。

关于hadoop - Hive 托管表与外部表 : LOCATION directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31310558/

相关文章:

Hadoop-mkdir : - Could not create the Java Virtual Machine

hadoop - 使用S3作为坚果存储系统

HADOOP - 在映射器中获取节点名

eclipse - HCatOutputFormat ClassNotFoundException

bash - 使用Shell解析HIVE中的字符串

maven - 使用命令mkdistro构建oozie 4.1.0时出错

linux - 乌兹 : Sqoop dynamic target directory

sql - 如何根据 HiveQL 和 SQL 中特定列的子字符串进行选择?

sql - 如何在不丢失小时、分钟和秒的情况下向 Hive 时间戳添加天数

hadoop - 如何从Hive Query获取Map Reduce代码?