Hive内表和外表的区别
本文以例子的形式介绍一下Hive内表和外表的区别。例子共有4个:不带分区的内表、带分区的内表、不带分区的外表、带分区的外表。
1 不带分区的内表
#创建表
create table innerTable(id int,name string) row format delimited fields terminated by ‘|’;(show tables发现没有innerTable,只有innertable。不多说,记住了)
#从HDFS上加载数据
load data inpath ‘hdfs://master:9000/user/root/test/innerTable’ into table innertable; (查看HDFS上/user/root/test/innerTable,发现文件价innerTable还在,但是里面的文件已经不在了。去哪了,去innertable表中了)
#删除刚刚创建的表
drop table innertable;(到HDFS上看一下innertable文件夹及其中的文件都没有了。去哪了,删除表的时候删除了)
2 带分区的内表
#创建表
create table inner_table_with_p(id int,name string) partitioned by (part_num int);(HDFS 出现文件夹inner_table_with_p,文件夹中为空)
#从HDFS加载数据
load data inpath ‘hdfs://master:9000/user/root/test/innerTable/part1′ into table inner_table_with_p partition(part_num=1)(文件夹inner_table_with_p出现子文件夹part_num=1,innerTable中part1消失);
load data inpath ‘hdfs://master:9000/user/root/test/innerTable/part2′ into table inner_table_with_p partition(part_num=2)(文件夹inner_table_with_p出现子文件夹part_num=2,innerTable中part2消失);
load data inpath ‘hdfs://master:9000/user/root/test/innerTable/part3′ into table inner_table_with_p partition(part_num=3)(文件夹inner_table_with_p出现子文件夹part_num=3,innerTable中part3消失);
#删除分区
alter table inner_table_with_p drop partition(part_num=1);(part_num=1对应分区文件夹本删除)
#删除表
drop table inner_table_with_p;(HDFS上inner_table_with_p文件夹被删除)
3 不带分区的外表
创建表
create external table outer_table(id int,name string) row format delimited fields terminated by ‘|’; (hive仓储目录中出现outer_table)
加载数据
load data inpath ‘/user/root/test/outerTable/outer’ into table outer_table;(outer_table中出现子文件outer,outerTable中outer消失)
删除表
drop table outer_table; (outer_table及子文件outer依然存在,因为这是外表)
4 带分区的外表
创建表
create external table outer_table_with_p(id int,name string) partitioned by (part_num int) row format delimited fields terminated by ‘|’; (hive仓储目录中出现outer_table_with_p)
加载数据
load data inpath ‘/user/root/test/outerTable/part1′ into table outer_table_with_p partiton(part_num=1); (outer_table_with_p中出现子文件夹part_num=1)
load data inpath ‘/user/root/test/outerTable/part2′ into table outer_table_with_p partition(part_num=2);(outer_table_with_p中出现子文件夹part_num=2)
load data inpath ‘/user/root/test/outerTable/part3′ into table outer_table_with_p partition(part_num=3);(outer_table_with_p中出现子文件夹part_num=3)
删除分区
alter table outer_table_with_p drop partition(part_num=1);(HDFS上分区文件依旧存在)
删除表
drop table outer_table_with_p;(HDFS上对应数据依旧存在)
总结:
1 删除内表时,内表数据会一并删除;
2 删除外表时,外表数据依旧存在。
推荐阅读:
Hive本地独立模式安装 http://www.linuxidc.com/Linux/2013-06/86104.htm
[Hive] 完全分布式安装过程(MetaStore: MySQL) http://www.linuxidc.com/Linux/2013-05/84085.htm
Hive内表和外表的区别的更多相关文章
- hive内表和外表的创建、载入数据、区别
创建表 创建内表 create table customer( customerId int, firstName string, lastName STRING, birstDay timestam ...
- Hive的内表和外表以及分区表
1. 内表和外表的区别 内表和外表之间是通过关键字EXTERNAL来区分.删除表时: 内表:在删除时,既删除内表的元数据,也删除内表的数据 外表:删除时,仅仅删除外表的元数据. CREATE [EXT ...
- Hive 7、Hive 的内表、外表、分区(22)
Hive 7.Hive 的内表.外表.分区 1.Hive的内表 Hive 的内表,就是正常创建的表,在 http://www.cnblogs.com/raphael5200/p/5208437.h ...
- Hive 7、Hive 的内表、外表、分区
1.Hive的内表 Hive 的内表,就是正常创建的表,在 http://www.cnblogs.com/raphael5200/p/5208437.html 中已经提到: 2.Hive的外表 创建H ...
- hadoop-hive的内表和外表
--创建内表create table if not exists employee(id int comment 'empoyeeid',dateincompany string comment 'd ...
- Hive内外表的区分方法及内外部差异
Hive内外部区分方法 查看hive元数据:进入mysql中hive元数据库,查看TBLS表,查看对应的表名和表类型: 在hive-cli界面:desc extended tablename,查看Ta ...
- ABAP工作区,内表,标题行的定义和区别
工作区域跟变量一样,是用来保存数据的.区别是变量只能从中保存一个数据.而工作区域可以存放多个.把多个数据合在一起就成工作区域了.下面我们来看看工作区域是如何定义的吧.定义有四种方法,如下:1 ...
- hive内部表与外部表区别
1.在Hive里面创建一个表: hive> create table wyp(id int, > name string, > age int, > tele ...
- hive 内部表与外部表的区别
hive 内部表: hive> create table soyo55(name STRING,addr STRING,money STRING) row format delimited fi ...
随机推荐
- Java学习笔记——双等号和equals的区别
一.==和equals的区别 1. ==可以用来比较基本类型和引用类型,判断内容和内存地址 2. equals只能用来比较引用类型,它只判断内容.该函数存在于老祖宗类 java.lang.Object ...
- Java学习笔记——字符串常用函数
class JavaTest4_String { public static void main(String[] args) { String str1 = "IOS,ANDROID,BB ...
- 使你的 Google Summer of Code 建议被接收的5个技巧
本文翻译自:http://www.di.ens.fr/~baghdadi/TXT_blog/5_advices_to_get_your_proposal_accepted.lyx.html 本文讲的主 ...
- MySQL 中随机抽样:order by rand limit 的替代方案
最近由于需要大概研究了一下MYSQL的随机抽取实现方法.举个例子,要从tablename表中随机提取一条记录,大家一般的写法就是:SELECT * FROM tablename ORDER BY RA ...
- Matlab之cell使用
1.声明 (1) DataCell = cell(1,N);(2) DataCell{N} = []; 如何赋值呢? a{1,1}=rand(5) 那么a的1行1列的单元中存储的就是一个随机的5×5的 ...
- nginx二级域名配置
CentOs下nginx二级域名配置 域名配置文件 命名规则:XXX.域名信息.conf 配置文件路径:etc/nginx/conf.d/xxxx.conf 配置文件内容:server { liste ...
- 跟我学习dubbo-Dubbo管理控制台的安装(3)
Dubbo管理控制台的安装 1.Dubbo管理控制台的主要作用:服务治理 2.管理控制台主要包含: 路由规则 动态配置 服务降级 访问控制 权重调整 负载均衡等管理功能 3.管理控制台版本: 当前稳定 ...
- SQLite&&SharedPreferences&&IO读写Sdcard学习笔记
SQLite 轻量级的.嵌入式的.关系型数据库 Android.IOS等广泛使用的的数据库系统 SQLite数据库之中可以方便的使用SQL语句,实现数据的增加.修改.删除.查询等操作 SQLiteOp ...
- PHP 创建重用数据库连接函数 mysqli与PDO
代码如下: 有兴趣的可以测试下 摘自于某书 <? php public function dbConnect( $usertype, $connectionType = 'mysqli' ) { ...
- 理解C#系列 / C#语言的特性
C#语言的特性 大多数语句都已(;)结尾 用({})定义语句块 单行注释(//),多行注释(/*......*/)智能注释(///) 区分大小写 用namespace名称空间对类进行分类 在C#中的所 ...