学习 Hive(十一):视图

Hive 视图是逻辑视图,即只保存元数据不保存数据。视图是封装思想的体现,隐藏了视图复杂的处理(过滤、子查询、分组、连接等),简化了查询。视图是只读的。

视图定义

CREATE VIEW IF NOT EXISTS order_summary  
AS  
SELECT  
  order_id,
  SUM(amount) AS total_amount
FROM order_item  
GROUP BY order_id  

删除视图

DROP VIEW IF EXESTS order_summary  

修改视图

ALTER VIEW order_summary  
AS  
SELECT  
  order_id,
  SUM(amount) AS total_amount
FROM order_item  
GROUP BY order_id  

查看视图

SHOW CREATE TABLE order_summary