hive视图
數(shù)據(jù)
數(shù)據(jù)文件v_t1
[root@hello110 data]# vi v_t1
lisi ? ?22 ? ? ?100000
ximing ?22 ? ? ?100022
xiaoji ?23 ? ? ?100033
xiaohua 24 ? ? ?100044
xx ? ? ?22 ? ? ?100055
數(shù)據(jù)文件v_t2
[root@hello110 data]# vi v_t2
lisi ? ?23 ? ? ?100000
ximing ?22 ? ? ?100022
xiaoji ?23 ? ? ?100033
xiaohua 24 ? ? ?100044
xx1 ? ? 22 ? ? ?100055
xx2 ? ? 22 ? ? ?100066
xx3 ? ? 22 ? ? ?100077
創(chuàng)建測試表v_t1
hive (zmgdb)> create table v_t1(name string,age int,slary int)
? ? ? ? ? ? > row format delimited fields terminated by '\t';
創(chuàng)建測試表v_t2
hive (zmgdb)> create table v_t2(name string,age int,slary int)
? ? ? ? ? ? > row format delimited fields terminated by '\t';??
導入數(shù)據(jù)
hive (zmgdb)> load data local inpath '/data/v_t1' into table v_t1;
Loading data to table zmgdb.v_t1
OK
hive (zmgdb)> load data local inpath '/data/v_t2' into table v_t2;
Loading data to table zmgdb.v_t2
OK
創(chuàng)建視圖
hive (zmgdb)> create view view_t1t2?
? ? ? ? ? ? > as
? ? ? ? ? ? > select t1.age,t1.name as t1name,t1.slary as t1slary,t2.name as t2name,t2.slary as t2slary?
?? ? ? >?from v_t1 t1,v_t2 t2
? ? ? ? ? ? > where t1.age=t2.age;
OK
age ? ? t1name ?t1slary t2name ?t2slary
Time taken: 0.141 seconds
PS:視圖的字段名不能重復。如果相同會報?FAILED: SemanticException [Error 10036]: Duplicate column name:
查詢視圖
hive (zmgdb)> select * from view_t1t2;
hive會啟動MapReduce
hive (zmgdb)> show tables;
OK
tab_name
bucket_t1
bucket_t2
bucket_t3
p_t1
p_t3
p_t4
t1
t2
v_t1
v_t2
view_t1t2
刪除視圖
drop view if exists v1;
補充
view只存在hive的metastore 中,不存在hadoop中。
總結(jié)
- 上一篇: android虚拟机鼠标左键拖动会输入C
- 下一篇: visual studio过期登录不了账