Hive的数据模型之外部表
一 外部表(External Table)
1、指向已经在HDFS中存在的数据,可以创建Partition。
2、它和内部表在元数据的组织上是相同的,而实际数据的存储则有较大的差异。
3、外部表只是一个过程,加载数据和创建表同时完成,并不会移动到数据仓库目录中,只是与外部数据建立一个链接。当删除一个外部表时,仅删除该链接。
二 理解外部表
三 实战
1、加入外部数据
[[email protected] ~]# ls student0*
student01.txt student02.txt student03.txt
[[email protected] ~]# more student01.txt
Tom,23
Mary,20
[[email protected] ~]# more student02.txt
Mike,25
[[email protected] ~]# more student03.txt
Scott,21
King,20
[[email protected] ~]# hadoop fs -put student01.txt input
Warning: $HADOOP_HOME is deprecated.
[[email protected] ~]# hadoop fs -put student02.txt input
Warning: $HADOOP_HOME is deprecated.
[[email protected] ~]# hadoop fs -put student03.txt input
Warning: $HADOOP_HOME is deprecated.
加入文件后:
2、创建外部表
hive> create external table external_student
> (sname string,age int)
> row format delimited fields terminated by ','
> location '/user/root/input';
OK
Time taken: 1.583 seconds
3、查询结果
hive> select * from external_student;
OK
Tom 23
Mary 20
Mike 25
Scott 21
King 20
Time taken: 0.178 seconds, Fetched: 5 row(s)