内部表&外部表

未被external修饰的是内部表(managed table),被external修饰的为外部表(external table);
区别:
内部表数据由Hive自身管理,外部表数据由HDFS管理;
内部表数据存储的位置是hive.metastore.warehouse.dir(默认:/user/hive/warehouse),外部表数据的存储位置由自己制定(如果没有LOCATION,Hive将在HDFS上的/user/hive/warehouse文件夹下以外部表的表名创建一个文件夹,并将属于这个表的数据存放在这里);
删除内部表会直接删除元数据(metadata)及存储数据;删除外部表仅仅会删除元数据,HDFS上的文件并不会被删除;
对内部表的修改会将修改直接同步给元数据,而对外部表的表结构和分区进行修改,则需要修复(MSCK REPAIR TABLE table_name;)

如下,进行试验进行理解

试验理解

创建内部表t1

create table t1(id      int,name    string,hobby   array<string>,add     map<String,string>
)
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 ...)]

创建一个文件粘贴上述记录,并上载即可,如下图:

文件内容如下

1,xiaoming,book-TV-code,beijing:chaoyang-shagnhai:pudong
2,lilei,book-code,nanjing:jiangning-taiwan:taibei
3,lihua,music-book,heilongjiang:haerbin

然后上载

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<string>,add     map<String,string>
)
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<string>,add     map<String,string>
)
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内部表和外部表的区别详解相关推荐

  1. mysql某个表被行锁了_MySQL 行锁和表锁的含义及区别详解

    一.前言 对于行锁和表锁的含义区别,在面试中应该是高频出现的,我们应该对MySQL中的锁有一个系统的认识,更详细的需要自行查阅资料,本篇为概括性的总结回答. MySQL常用引擎有MyISAM和Inno ...

  2. hive内部表与外部表区别

    1.创建内部表与外部表的区别是什么? 2.external关键字的作用是什么? 3.外部表与内部表的区别是什么? 4.删除表的时候,内部表与外部表有什么区别? 5.load data local in ...

  3. Hive内部表与外部表区别详细介绍

    文章转载自:http://www.aboutyun.com/thread-7458-1-1.html 1.创建内部表与外部表的区别是什么? 2.external关键字的作用是什么? 3.外部表与内部表 ...

  4. hive中内部表和外部表有什么区别?一般什么时候使用内部表什么时候使用外部表?

    hive中内部表和外部表有什么区别? 在使用hive搭建数据仓库的时候,可以建立两种表格.一种是内部表(managed table),一种是外部表(external table). 内部表建表是不加修 ...

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

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

  6. Hive 内部表与外部表

    首先查看当前的表: 内部表 查看emp表: 查看这个emp表的详细信息: 可以看到Table Type是一个MANAGED_TABLE,就是所谓的内部表 内部表跟外部表有什么区别 首先看一下mysql ...

  7. hive 创建表_2min快速了解,Hive内部表和外部表

    在了解内部表和外部表区别前, 我们需要先了解一下Hive架构 : 大家可以简单看一下这个架构图,我介绍其中要点: Hive的数据分为两种,一种为普通数据,一种为元数据. 元数据存储着表的基本信息,增删 ...

  8. hive内部表与外部表入门

    表分类 在Hive中,表类型主要分为两种, 第一种:内部表 也叫管理表 表目录会创建在集群上的{hive.metastore.warehouse.dir}下的相应的库对应的目录中. 默认创建的表就是内 ...

  9. hive中的内部表和外部表

    未被external修饰的是内部表(managed table),被external修饰的为外部表(external table). 区别 1.  内部表数据由Hive自身管理,外部表数据由HDFS管 ...

  10. 27.大数据---Hive的数据库和表的基本操作;脚本化运行;内部表;外部表;分区表

    一 . Hive 基本操作 1. 数据库操作(增.删.改.查) 1.1 创建数据库 create database if not exists test_001; 使用数据库 use test_001 ...

最新文章

  1. HDU 3790 最短路径问题
  2. 信息学奥赛一本通(2022:【例4.7】最小n值)
  3. 防止a标签跳转的几种方法
  4. SQLite 3.30.0 发布,世界上使用量最大的数据库引擎
  5. 使用JAVASCRIPT进行全屏显示页面,就像触摸屏显示效果
  6. 拼音表大全图_20x11二层带阁楼别墅设计图纸及效果图大全
  7. 阿里巴巴早期发展简史
  8. 思科网络工程师面试题
  9. Latex 中的空格汇总
  10. 数据库原理第三章习题作业
  11. uni-app开发中的#ifdef MP是什么意思?条件编译
  12. wjw的剪纸(DFS)
  13. xp系统计算机怎么连接到网络打印机,WinXP电脑如何添加网络打印机?WinXP添加网络打印机的步骤...
  14. 又一家硅谷巨头掀裁员潮!员工称像经历一场“屠杀”
  15. Interaction triggers in WPF
  16. Assisted Excitation of Activations:A Learning Technique to Improve Object Detectors论文解读
  17. 单用户登录记录互踢下线思路
  18. 实例5:身体质量指数BMI
  19. xp怎样修改计算机mac地址,xp操作系统网卡mac地址的修改方法
  20. 网络安全行业一览众山小,你家公司上榜了吗

热门文章

  1. CGAN和InfoGAN理解
  2. 5mm方格本打印模板_自制方格本模板
  3. 三角网导线平差实例_三角网条件平差计算
  4. 都能看懂的嵌入式linux/android alsa_aplay alsa_amixer命令行使用方法
  5. ubuntu重装显卡驱动
  6. Android adb 常用命令
  7. ACM MM论文放榜!淘系技术内容互动算法团队4篇论文入选!
  8. 反编译apk,修改登录成功
  9. 阿拉德之怒手游超详细图文架设教程
  10. 战地4无限加入服务器,战地1怎么加入服务器