未被external修饰的是内部表(managed table),被external修饰的为外部表(external table);

区别:

内部表数据由Hive自身管理,外部表数据由HDFS管理;

内部表数据存储的位置是hive.metastore.warehouse.dir(默认:/user/hive/warehouse),外部表数据的存储位置由自己制定;

删除内部表会直接删除元数据(metadata)及存储数据;删除外部表仅仅会删除元数据,HDFS上的文件并不会被删除;

对内部表的修改会将修改直接同步给元数据,而对外部表的表结构和分区进行修改,则需要修复(MSCK REPAIR TABLE table_name;)

如下,进行试验进行理解

试验理解

创建内部表t1

create table t1(

id      int

,name    string

,hobby   array

,add     map

)

row format delimited

fields terminated by ','

collection items terminated by '-'

map keys terminated by ':'

;

2. 查看表的描述:desc t1;

装载数据(t1)

注:一般很少用insert (不是insert overwrite)语句,因为就算就算插入一条数据,也会调用MapReduce,这里我们选择Load Data的方式。

LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename [PARTITION (partcol1=val1, partcol2=val2 ...)]

然后上载

load data local inpath '/home/hadoop/Desktop/data' overwrite into table t1;

别忘记写文件名/data,笔者第一次忘记写,把整个Desktop上传了,一查全是null和乱码。。。。

查看表内容:

select * from t1;

创建一个外部表t2

create external table t2(

id      int

,name    string

,hobby   array

,add     map

)

row format delimited

fields terminated by ','

collection items terminated by '-'

map keys terminated by ':'

location '/user/t2'

;

装载数据(t2)

load data local inpath '/home/hadoop/Desktop/data' overwrite into table t2;

查看文件位置

我们在NameNode:50070/explorer.html#/user/目录下,可以看到t2文件

t1在哪呢?在我们之前配置的默认路径里

同样我们可以通过命令行获得两者的位置信息:

desc formatted table_name;

这里写图片描述

这里写图片描述

注:图中managed table就是内部表,而external table就是外部表。

分别删除内部表和外部表

下面分别删除内部表和外部表,查看区别

观察HDFS上的文件

发现t1已经不存在了

这里写图片描述

但是t2仍然存在

这里写图片描述

因而外部表仅仅删除元数据

重新创建外部表t2

create external table t2(

id      int

,name    string

,hobby   array

,add     map

)

row format delimited

fields terminated by ','

collection items terminated by '-'

map keys terminated by ':'

location '/user/t2'

;

这里写图片描述

不往里面插入数据,我们select * 看看结果

这里写图片描述

可见数据仍然在!!!

官网介绍

以下是官网中关于external表的介绍:

A table created without the EXTERNAL clause is called a managed table because Hive manages its data.

Managed and External Tables

By default Hive creates managed tables, where files, metadata and statistics are managed by internal Hive processes. A managed table is stored under the hive.metastore.warehouse.dir path property, by default in a folder path similar to /apps/hive/warehouse/databasename.db/tablename/. The default location can be overridden by the location property during table creation. If a managed table or partition is dropped, the data and metadata associated with that table or partition are deleted. If the PURGE option is not specified, the data is moved to a trash folder for a defined duration.

Use managed tables when Hive should manage the lifecycle of the table, or when generating temporary tables.

An external table describes the metadata / schema on external files. External table files can be accessed and managed by processes outside of Hive. External tables can access data stored in sources such as Azure Storage Volumes (ASV) or remote HDFS locations. If the structure or partitioning of an external table is changed, an MSCK REPAIR TABLE table_name statement can be used to refresh metadata information.

Use external tables when files are already present or in remote locations, and the files should remain even if the table is dropped.

Managed or external tables can be identified using the DESCRIBE FORMATTED table_name command, which will display either MANAGED_TABLE or EXTERNAL_TABLE depending on table type.

Statistics can be managed on internal and external tables and partitions for query optimization.

Hive官网介绍:

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-DescribeTable/View/Column

hive外部表改为内部表_hive内部表外部表介绍相关推荐

  1. hive外部表改为内部表_3000字揭秘Greenplum的外部数据加载——外部表

    外部表是greenplum的一种数据表,它与普通表不同的地方是:外部表是用来访问存储在greenplum数据库之外的数据.如普通表一样,可使用SQL对外部表进行查询和插入操作.外部表主要用于Green ...

  2. hive load data inpath 空目录_Hive内部表 | 每日五分钟学大数据

    上一篇说的是外部表,当把EXTERNAL关键字去掉的时候就是内部表了.为什么叫内部表,因为这种表,Hive会(或多或少地)控制着数据的生命周期. 如果你熟悉Hive那你一定知道,Hive默认情况下会将 ...

  3. hive内部表和外部表的区别_3000字揭秘Greenplum的外部数据加载——外部表

    外部表是greenplum的一种数据表,它与普通表不同的地方是:外部表是用来访问存储在greenplum数据库之外的数据.如普通表一样,可使用SQL对外部表进行查询和插入操作.外部表主要用于Green ...

  4. hive根据已有表创建新表_Hive基础之创建表

    1.创建基础表 在这个网页里详细记录了创建表的每个语法,下面就一一来看这些创建表的语法内容: CREATE TABLE [IF NOT EXISTS] [db_name.]table_name ``[ ...

  5. hive查看数据库里库的信息_Hive学习之路 (三)Hive元数据信息对应MySQL数据库表...

    概述 Hive 的元数据信息通常存储在关系型数据库中,常用MySQL数据库作为元数据库管理.上一篇hive的安装也是将元数据信息存放在MySQL数据库中. Hive的元数据信息在MySQL数据中有57 ...

  6. Hive:命令行界面、数据类型、DDL数据定义(数据库及表操作/分区分桶)、DML数据操作(数据导入导出)

    目录 1.Hive命令行界面 1.1.选项列表 1.2.变量和属性 1.2.1.Hive中变量和属性命名空间 1.2.2.用户自定义变量 1.2.3..hiverc文件 1.3.一次使用的命令 1.4 ...

  7. Hive中元数据表的关系和如何在元数据中删除表

    各表之间主键的关系图 这个整理很不容易呀,能够更好地了解他们,其中有一种场景需要使用的 传统的方法删除这张表: 方式一:仅删除表中数据,保留表结构 truncate table 表名; (trunca ...

  8. 一篇文章彻底掌握 hive 中的 ORDER/SORT/CLUSTER/DISTRIBUTE BY 和 BUCKET 桶表

    大家好,我是明哥! 本片文章,我们来总结下,HIVE 中的 order/sort/cluster/distribute by 和 BUCKET 桶表 1 ORDER BY ORDER BY 会对 SQ ...

  9. oracle变更为大表分区表,叶摇 » Blog Archive » oracle把没有分区的普通大表改成分区表...

    oracle把没有分区的普通大表改成分区表 1.根据要改成分区的表的结构创建一张一样结构的表: create table PARA_CELL_W_HIS_EXCHANGE ( START_TIME D ...

最新文章

  1. ASP.NET中Cookie的使用(实战教程)
  2. [转] Transact_SQL手册
  3. 《构建之法》8.9.10
  4. npm 安装指定的第三方包
  5. YY/T 0664—2020《医疗器械软件 软件生存周期过程》 相关
  6. Git使用教程:真正手把手教你使用git!
  7. modSecurity规则学习(四)——规则指令编写
  8. 解决vi/vim中粘贴会在行首多很多缩进和空格的问题
  9. Python自动化开发课堂笔记【Day06】 - Python基础(模块)
  10. 项目在服务器的绝对路径,项目在云服务器上的绝对路径
  11. 向云上迁移数据时如何避免停机和中断
  12. 安卓中的乱码以及编码问题
  13. 当“双态IT”已成共识 如何打造以数据驱动的运维平台?
  14. android开发 自我优势_安卓程序员自我评价
  15. 艳照门事件发酵 谷歌称已删除数万张照片
  16. 叶俊:从佛说法制的十大好处谈到企业的制度与人情
  17. 马王堆版《道德经》--原原本本的帛书版(转载)
  18. Thinkpad T440p安装Linux的种种问题(by quqi99)
  19. 报错:UnicodeDecodeError:: ‘utf-8‘ codec can‘t decode byte 0xc8 in position 0: invalid contin
  20. amixer alsa

热门文章

  1. TensorFlow的基本使用
  2. c/c++操作mysql数据库使用utf8总结
  3. 大剑无锋之简单介绍一下虚拟内存【面试推荐】
  4. 大剑无锋之SQL求用户最近的登录时间【面试推荐】
  5. leetcode 304. Range Sum Query 2D - Immutable |304. 二维区域和检索 - 矩阵不可变(二维前缀和问题)
  6. 【GitHub】如何合并分支?
  7. spark写入elasticsearch限流
  8. HipHop算法:利用微博互动关系挖掘社交圈
  9. 5行代码满分——L1-060 心理阴影面积 (5分)
  10. 高效万进制——蓝桥杯|HDOJ 1002 大数加法——30行代码AC