Hive的数据模型之外部表

外部表(External Table)
- 指向已经在HDFS中存在的数据,可以创建Partition
- 它和内部表在元数据的组织上是相同的,而实际数据的存储则有较大的差异。
- 外部表侄有一个过程,加载数据和创建表同时完成,并不会移动到数据仓库目录中,只是与外部数据建立一个链接。当删除一个外部表时,仅删除该链接。

1、准备几张相同数据结构的数据txt文件,放在HDFS的/input 目录下。
2、在hive下创建一张有相同数据结构的外部表external_student,location设置为HDFS的/input 目录。则external_student会自动关连/input 下的文件。
3、查询外部表。显示/input下具有相同数据结构的所有文件的数据。
4、删除/input目录下的部分文件。
5、查询外部表。删除的那部分文件数据不存在。
6、将删除的文件放入/input目录。
7、查询外部表。放入的那部分文件数据重现。

举例如下:

(1)准备数据:

student1.txt
1,Tom,M,60,80,96
2,Mary,F,11,22,33 student2.txt
3,Jerry,M,90,11,23 student3.txt
4,Rose,M,78,77,76
5,Mike,F,99,98,98
查看HDFS文件系统现有的目录。
# hdfs dfs -ls / 创建input目录。
# hdfs dfs -mkdir /input
将文件放入HDFS文件系统
hdfs dfs -put localFileName hdfsFileDir
# hdfs dfs -put student1.txt /input
# hdfs dfs -put student2.txt /input
# hdfs dfs -put student3.txt /input

(2)创建外部表

create table external_student
(sid int, sname string, gender string, language int, math int, english int)
row format delimited fields terminated by ','
location '/input';

(3)查询外部表

select * from external_student;

(4)删除HDFS上的student1.txt

# hdfs dfs -rm /input/student1.txt

(5)查询外部表

select * from external_student;

(6)将student1.txt 重新放入HDFS input目录下

# hdfs dfs -put student1.txt /input

(7)查询外部表

select * from external_student;

最新文章

  1. C#中Dictionary<TKey,TValue>排序方式
  2. webservice入门(2)开发ws程序
  3. 转:用WCAT进行IIS压力测试
  4. COALESCE NVL NVL2 DECODE
  5. linux下php-fpm 启动参数及重要配置
  6. JVM系列三:JVM参数设置、分析
  7. C++学习14 继承的概念及语法
  8. Codeforces Round #260 (Div. 1) C. Civilization 并查集,直径
  9. Hive over HBase和Hive over HDFS性能比较分析
  10. Java Web SSH框架总是无法写入无法读取Cookie
  11. 对于方法 String.Contains,只支持可在客户端上求值的参数。
  12. 有关SetTimer函数的用法
  13. JavaWeb核心编程之Tomcat安装和配置
  14. linux yum命令
  15. hdu 1251 统计拼图
  16. [读书心得] .NET中 类型,对象,线程栈,托管堆在运行时的关系
  17. 详解equals()方法和hashCode()方法
  18. 在myeclipse的jsp编辑器中怎么把Source/Preview调出来的方法步骤
  19. phpexcel用法(转)
  20. 【linux】awk相关

热门文章

  1. IDEAL葵花宝典:java代码开发规范插件:GsonFormat插件将JSONObject格式的String 解析成实体
  2. swoole_table
  3. mybatis进行分页,使用limit
  4. listen 56
  5. hls协议(最清晰的讲解)
  6. selenium 经常用到的API
  7. xml字符串的解析
  8. android自定义控件(一) 官方文档的翻译
  9. CodeForces - 697F:Legen... (AC自动机+矩阵)
  10. MySQL文本处理函数2_20160921