HiveQL:视图

来源:互联网 发布:linux 脚本 while 编辑:程序博客网 时间:2024/03/28 21:30
使用视图来降低查询复杂度
当查询变得很长或复杂的时候,通过使用视图将这个查询语句分隔成多个小的、更可控的片段可以降低这种复杂度。
eg:
from ( select * from people join cart on (cart.people_id=people.id) where firstname='john') a select a.lastname where a.id=3 ;

可以将嵌套子查询变成一个视图:
create view shorter as select * from people join cart on   (cart.people_id=people.id) where firstname='john' ;

使用视图来限制基于条件过滤的数据
对于视图来说一个常见的使用场景就是基于一个或多个列的值来限制输出结果。有些数据库允许将视图作为一个安全机制,也就是不给用户直接访问具有敏感数据的原始表,而是提供给用户一个通过where字句限制了的视图,以供访问。
eg:
create table emp (firstname string,lastname string,ssn string,pwd string,depart string) ;
create view mid_emp as select firstname,lastname,ssn from emp where depart='0908' ;

动态分区中的视图和map类型
create view orders(state,city,part) as select cols['state'],cols['city'],cols['part'] from dynamictable where cols['type']='request' ;

视图零零碎碎相关的事情
create view if not exists ship(time,part) 
commont '...'
tblproperties('creator'='me')
as select ...

create table ship2 like ship ;
drop view if exists ship ;
alter view ship set tblproperties('created_at'='some_timestamp');
0 0
原创粉丝点击