hive内部表&外部表介绍
未被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<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 ...)]
然后上载
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内部表&外部表介绍的更多相关文章
- 第2节 hive基本操作:9、hive当中创建外部表的语法及外部表的操作&分区表的语法和操作
外部表: 外部表说明: 外部表因为是指定其他的hdfs路径的数据加载到表当中来,所以hive表会认为自己不完全独占这份数据,所以删除hive表的时候,数据仍然存放在hdfs当中,不会删掉 管理表和外部 ...
- Hive 文件格式 & Hive操作(外部表、内部表、区、桶、视图、索引、join用法、内置操作符与函数、复合类型、用户自定义函数UDF、查询优化和权限控制)
本博文的主要内容如下: Hive文件存储格式 Hive 操作之表操作:创建外.内部表 Hive操作之表操作:表查询 Hive操作之表操作:数据加载 Hive操作之表操作:插入单表.插入多表 Hive语 ...
- Hive基础(5)---内部表 外部表 临时表
1.外部表 关键字:EXTERNAL 外部表创建时需要指定LOCATION 删除外部表时,数据不被删除 CREATE EXTERNAL TABLE page_view(viewTime INT, us ...
- hive 四种表,分区表,内部,外部表,桶表
Hive四大表类型内部表.外部表.分区表和桶表 一.概述 总体上Hive有四种表:外部表,内部表(管理表),分区表,桶表.分别对应不同的需求.下面主要讲解各种表的适用情形.创建和加载数据方法. 二.具 ...
- Hive内部表外部表转化分析(装)
link:http://anyoneking.com/archives/127hive表分为内部表和外部表.外部表在删除的时候并不会删除到hdfs中的文件,比较安全,所以对于重要的需要进行分析的日志建 ...
- 分区表,桶表,外部表,以及hive一些命令行小工具
hive中的表与hdfs中的文件通过metastore关联起来的.Hive的数据模型:内部表,分区表,外部表,桶表受控表(managed table):包括内部表,分区表,桶表 内部表: 我们删除表的 ...
- oracle-对象表-外部表
http://www.blogjava.net/decode360/archive/2008/10/16/286802.html create or replace type person as ob ...
- hive内部表与外部表区别详细介绍
问题导读:1.创建内部表与外部表的区别是什么?2.external关键字的作用是什么?3.外部表与内部表的区别是什么?4.删除表的时候,内部表与外部表有什么区别?5.load data local i ...
- hive内部表、外部表
hive内部表.外部表区别自不用说,可实际用的时候还是要小心. Hive的数据分为表数据和元数据,表数据是Hive中表格(table)具有的数据:而元数据是用来存储表的名字,表的列和分区及其属性,表的 ...
随机推荐
- linux 给指定用户分配文件夹权限
1.更改目录所有者命令:chown -R 用户名称 目录名称2.更改目录权限命令:chmod -R 755 目录名称3.查看文件夹的权限ls -la 目录
- javascript获取网页宽高,屏幕宽高,屏幕分辨率等
<script> var s = ""; s += "\r\n网页可见区域宽:"+ document.body.clientWidth; s + ...
- 关于tomcat中的三个端口的作用及其相关细节
[一]端口内容 tomcat的端口号相关信息: Tomcat admin port——管理端口,允许你远程配置tomcat HTTP——正常的http协议 AJP——Apache JServ Prot ...
- Java程序员必精通之—synchronized
更多Java并发文章:https://www.cnblogs.com/hello-shf/category/1619780.html 一.简介 相信每一个java程序员对synchronized都不会 ...
- python学习笔记之数据类型、字符编码、文件处理
1.数据类型 1.数字(int,float) 整形(int):定义 age=20 #本质age=int(20) 浮点类型:salary=3000.3 #本质salary=float(3000.3) ...
- Cocos2d-x之Label
| 版权声明:本文为博主原创文章,未经博主允许不得转载. 在游戏开发中经常会使用标签文字,例如,游戏介绍,玩家积分,菜单选项,文字提示等等. LabelTTF 直接支持使用 TTF 字库 ...
- JVM系列(一) — Jvm内存模型
总结自<深入理解java虚拟机> 很多博客在讲虚拟机内存模型时,比较宽泛或者粗化,甚者,不准确,以下是我的一个笔记照片 运行时数据区可以分为两部分:线程共享区和线程私有区 一.线程共享区 ...
- Centos 安装vnc / vncserver
一.安装 以root用户运行以下命令来安装vncserver; yum install tigervnc-server 同样运行以下命令来安装vncviewer; yum install vnc 停止 ...
- DB2实例
实例是逻辑数据库管理环境,可以在此环境中对数据库进行编目和设置配置参数.根据需要, 可以在一台服务器上创建多个实例,该服务器为每个实例提供唯一的数据库服务器环境. 默认实例:DB2 显示实例: ...
- number框
因为系统的number框无法设置样式,所以休息无聊时写了一个简单的模拟number框的插件,效果不是很完善,有一些功能可能没注意到 // 简单的模拟number框插件 // 布局: // <di ...