本文以例子的形式介绍一下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内表和外表的区别的更多相关文章

  1. hive内表和外表的创建、载入数据、区别

    创建表 创建内表 create table customer( customerId int, firstName string, lastName STRING, birstDay timestam ...

  2. Hive的内表和外表以及分区表

    1. 内表和外表的区别 内表和外表之间是通过关键字EXTERNAL来区分.删除表时: 内表:在删除时,既删除内表的元数据,也删除内表的数据 外表:删除时,仅仅删除外表的元数据. CREATE [EXT ...

  3. Hive 7、Hive 的内表、外表、分区(22)

    Hive 7.Hive 的内表.外表.分区   1.Hive的内表 Hive 的内表,就是正常创建的表,在 http://www.cnblogs.com/raphael5200/p/5208437.h ...

  4. Hive 7、Hive 的内表、外表、分区

    1.Hive的内表 Hive 的内表,就是正常创建的表,在 http://www.cnblogs.com/raphael5200/p/5208437.html 中已经提到: 2.Hive的外表 创建H ...

  5. hadoop-hive的内表和外表

    --创建内表create table if not exists employee(id int comment 'empoyeeid',dateincompany string comment 'd ...

  6. Hive内外表的区分方法及内外部差异

    Hive内外部区分方法 查看hive元数据:进入mysql中hive元数据库,查看TBLS表,查看对应的表名和表类型: 在hive-cli界面:desc extended tablename,查看Ta ...

  7. ABAP工作区,内表,标题行的定义和区别

         工作区域跟变量一样,是用来保存数据的.区别是变量只能从中保存一个数据.而工作区域可以存放多个.把多个数据合在一起就成工作区域了.下面我们来看看工作区域是如何定义的吧.定义有四种方法,如下:1 ...

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

    1.在Hive里面创建一个表: hive> create table wyp(id int,    > name string,    > age int,    > tele ...

  9. hive 内部表与外部表的区别

    hive 内部表: hive> create table soyo55(name STRING,addr STRING,money STRING) row format delimited fi ...

随机推荐

  1. android 使用<merge>标签

    <merge /> 标签在你嵌套 Layout 时取消了 UI 层级中冗余的 ViewGroup .比如,如果你有一个 Layout 是一个竖直方向的 LinearLayout,其中包含两 ...

  2. [Android 开源项目学习]Android的UITableView(1)

         最近由于项目加急,手里有好多看了差不多的开源项目,其中好多是大家经常用到的.图片的缓存BitmapFun(Android的文档中),AfinalMap,下拉刷新PullToRefresh等等 ...

  3. Amazon全场满$35减$5 (需Facebook)

    在Amazon.com上建一个Wish List(创建Wish List后须点击“Manage your lists”,在“Privacy”那一栏选择“Public”或“Shared”,再回到这个链接 ...

  4. jq使用手册

    jq 使用手册   翻译整理:Young.J 官方网站:http://jquery.com    jQuery是一款同prototype一样优秀js开发库类,特别是对css和XPath的支持,使我们写 ...

  5. WPF全球化与本地化 (二)

    Visual Baml Visual Locbaml is a free and open-source software to simplify the task of WPF applicatio ...

  6. Common工具类的验证码类的使用(未实现验证)

    验证码接收 using System; using System.Collections.Generic; using System.Linq; using System.Web; using CZB ...

  7. 深入理解ThreadLocal(转)(2015年06月11日)

    注明:转自:http://my.oschina.net/clopopo/blog/149368 学习一个东西首先要知道为什么要引入它,就是我们能用它来干什么.所以我们先来看看ThreadLocal对我 ...

  8. oracle中的instr()

    INSTR (源字符串, 目标字符串, 起始位置, 匹配序号) 在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置.只检索一次,就是说从字符的开始 到字符的结尾就结束. ...

  9. Part 9 Sorting data in AngularJS

    To sort the data in Angular 1. Use orderBy filter     {{ orderBy_expression | orderBy : expression : ...

  10. (转)RabbitMQ消息队列(七):适用于云计算集群的远程调用(RPC)

    在云计算环境中,很多时候需要用它其他机器的计算资源,我们有可能会在接收到Message进行处理时,会把一部分计算任务分配到其他节点来完成.那么,RabbitMQ如何使用RPC呢?在本篇文章中,我们将会 ...