Hive视图<转>

来源:互联网 发布:c语言中怎么开多次根号 编辑:程序博客网 时间:2024/05/20 02:25
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
[plain] view plaincopy
  1. CREATE VIEW [IF NOT EXISTS] view_name [(column_name [COMMENT column_comment], ...) ]  
  2. [COMMENT view_comment]  
  3. [TBLPROPERTIES (property_name = property_value, ...)]  
  4. AS SELECT ...  
删除view
[plain] view plaincopy
  1. DROP VIEW [IF EXISTS] view_name  
修改view
[plain] view plaincopy
  1. ALTER VIEW view_name SET TBLPROPERTIES table_properties  
  2.   
  3. table_properties:  
  4.   : (property_name = property_value, property_name = property_value, ...)  

实例:

[plain] view plaincopy
  1. hive> desc student;  
  2. OK  
  3. id      int  
  4. name    string  
  5. academy string  
  6. class   string  
  7. Time taken: 0.146 seconds  
  8. hive> create view student_view (id, name_length) as  select id, length(name) from student;  
  9. OK  
  10. Time taken: 0.424 seconds  
  11. hive> desc student_view;  
  12. OK  
  13. id      int  
  14. name_length     int  
  15. Time taken: 0.071 secondshive> select * from student;  
  16. Total MapReduce jobs = 1  
  17. ......  
  18. Total MapReduce CPU Time Spent: 680 msec  
  19. 1       20      computer        034  
  20. 2       21      computer        034  
  21. 3       19      computer        034  
  22. 4       18      computer        034  
  23. 5       22      computer        034  
  24. 6       23      computer        034  
  25. 7       25      computer        034  
  26. 1       20      physics 034  
  27. 2       21      physics 034  
  28. 3       19      physics 034  
  29. 4       18      physics 034  
  30. 5       22      physics 034  
  31. 6       23      physics 034  
  32. 7       25      physics 034Time taken: 0.176 seconds  
  33. hive> select * from student_view;  
  34. Total MapReduce jobs = 1  
  35. ......  
  36. Total MapReduce CPU Time Spent: 680 msec  
  37. OK  
  38. 1       2  
  39. 2       2  
  40. 3       2  
  41. 4       2  
  42. 5       2  
  43. 6       2  
  44. 7       2  
  45. 1       2  
  46. 2       2  
  47. 3       2  
  48. 4       2  
  49. 5       2  
  50. 6       2  
  51. 7       2  
  52. Time taken: 20.592 secondshive> create view student_view_view(id)  
  53.     > as                                 
  54.     > select id from student_view;  
  55. OK  
  56. Time taken: 0.215 seconds  
  57. hive> select * from student_view_view;  
  58. Total MapReduce jobs = 1  
  59. .....  
  60. Total MapReduce CPU Time Spent: 790 msec  
  61. OK  
  62. 1  
  63. 2  
  64. 3  
  65. 4  
  66. 5  
  67. 6  
  68. 7  
  69. 1  
  70. 2  
  71. 3  
  72. 4  
  73. 5  
  74. 6  
  75. 7  



[plain] view plaincopy
  1. <pre></pre><span style="font-family:Arial,Helvetica,sans-serif"><span style="white-space:normal"></span></span>  
  2. <pre></pre>  
  3. <pre></pre>  
  4. <pre></pre>  
  5. <pre></pre>  
  6. <pre></pre>  
  7. <pre></pre>  
  8. <pre></pre>  
  9. <pre></pre>  
  10. <pre></pre>  
  11. <pre></pre>  
  12. <pre></pre>  
  13. <pre></pre>  
  14. <pre></pre>  
0 0
原创粉丝点击