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 ...
随机推荐
- linux初学 :linux 常用命令(二)
压缩和解压命令 gzip/guzip zip/unzip tar gzip和gunzip一般可用参数是-r,例: gzip test.txt 压缩文件 gzip -r test 压缩所有tes ...
- tornado 杂记
一.建立一个简单的 hello world 网页 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import tornado.iolo ...
- Python_使用smtplib和email模块发送邮件
[http://blog.csdn.net/menglei8625/article/details/7721746] SMTP (Simple Mail Transfer Protocol) 邮件传送 ...
- canvas-js贝塞尔曲线代码在线生成工具
详细内容请点击 canvas贝塞尔曲线代码在线生成工具 可以快速生成二次.三次贝塞尔曲线的源码生成器,方便经常使用到canvas画图的同学使用,可以直接预览效果随意画出自己想要的图像. 生成源码效果预 ...
- Top 10 Programming Fonts
Top 10 Programming Fonts Sunday, 17 May 2009 • Permalink Update: This post was written back in 2009, ...
- Android Studio 1.3新版体验
Google发布的Android Studio最新版是 1.3 版,上周的I/O大会中三位Google工程师对Android Studio作了将近1小时的演讲: 之前一直习惯用Eclipse luna ...
- android 底部tabview模板
以下只是我个人的浅见,大神请忽略~ 底部tab的实现如下图: 现在实现这种界面是有很多方法的,但是对于android新手来说,实现这样的界面还是有难度的. 在网上找到了一个别人写好的底部tab模板,修 ...
- HDU4268 Alice and Bob(贪心+multiset)
Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...
- Js判断CSS文件加载完毕的实例教程
要判断这个 CSS 文件是否加载完毕,各个浏览器的做法差异比较大,这次要说IE浏览器做的不错,我们可以直接通过onload方法来处理CSS加载完成以后的处理: 代码如下 复制代码 // 代码节选至se ...
- C#读写日志文本文件
日志为文本文件每列以制表符隔开 行以换行符隔开 本次示例简单实现如下相关功能:1.正写日志文本 最新的日志放后面2.倒写日志文本 最新的日志放前面3.读日志文本内容显示在Label4.读日志文本内容到 ...