hive 视图

Hive 0.6版本及以上支持视图
Hive View具有以下特点:
1. View是逻辑存在,Hive暂不支持物化视图(1.0.3)
2. View只读,不支持LOAD/INSERT/ALTER。需要改变View定义,可以是用Alter View
3. View内可能包含ORDER BY/LIMIT语句,假如一个针对view的查询也包含这些语句, 则view中的语句优先级高。例如,定义view数据为limit 10, 针对view的查询limit 20,则最多返回10条数据。
4. Hive支持迭代视图

创建View
CREATE VIEW [IF NOT EXISTS] view_name [(column_name [COMMENT column_comment], ...) ]
[COMMENT view_comment]
[TBLPROPERTIES (property_name = property_value, ...)]
AS SELECT ...
删除view
DROP VIEW [IF EXISTS] view_name
修改view
ALTER VIEW view_name SET TBLPROPERTIES table_properties

table_properties:
  : (property_name = property_value, property_name = property_value, ...)

实例:

hive> desc student;
OK
id      int
name    string
academy string
class   string
Time taken: 0.146 seconds
hive> create view student_view (id, name_length) as  select id, length(name) from student;
OK
Time taken: 0.424 seconds
hive> desc student_view;
OK
id      int
name_length     int
Time taken: 0.071 secondshive> select * from student;
Total MapReduce jobs = 1
......
Total MapReduce CPU Time Spent: 680 msec
1       20      computer        034
2       21      computer        034
3       19      computer        034
4       18      computer        034
5       22      computer        034
6       23      computer        034
7       25      computer        034
1       20      physics 034
2       21      physics 034
3       19      physics 034
4       18      physics 034
5       22      physics 034
6       23      physics 034
7       25      physics 034Time taken: 0.176 seconds
hive> select * from student_view;
Total MapReduce jobs = 1
......
Total MapReduce CPU Time Spent: 680 msec
OK
1       2
2       2
3       2
4       2
5       2
6       2
7       2
1       2
2       2
3       2
4       2
5       2
6       2
7       2
Time taken: 20.592 secondshive> create view student_view_view(id)
    > as                               
    > select id from student_view;
OK
Time taken: 0.215 seconds
hive> select * from student_view_view;
Total MapReduce jobs = 1
.....
Total MapReduce CPU Time Spent: 790 msec
OK
1
2
3
4
5
6
7
1
2
3
4
5
6
7

















   

你可能感兴趣的:(mapreduce,properties,table,jobs)