2017-07-06 29 views
0

我有這個模式(通過DDL表和視圖給出):Hive Optimizer在優化視圖查詢時考慮視圖定義嗎?

hive> create table t_realtime(cust_id int, name string, status string, active_flag int); 

hive> create table t_hdfs(cust_id int, name string, status string, active_flag int); 

hive> create view t_inactive as select * from t_hdfs where active_flag=0; 

hive> create view t_view as select * from t_realtime union all select * from t_inactive; 

如果我火了查詢,如下所示:

hive> select * from t_view where active_flag = 1; 

這個查詢非常不應該訪問t_inactive觀點或t_hdfs在所有因爲t_inactive本身的視圖定義具有active_flag = 0而查詢謂詞具有active_flag = 1。但是,默認情況下,它不會消除此聯合視圖的t_inactive部分。

有沒有辦法實現這樣的蜂巢查詢?也許一些蜂巢優化參數或提示?

+1

根據您決定「默認情況下,它不會消除此聯合視圖的t_inactive部分」。 –

回答

1
hive> explain extended select * from t_view where active_flag = 1; 
OK 
STAGE DEPENDENCIES: 
    Stage-0 is a root stage 

STAGE PLANS: 
    Stage: Stage-0 
    Fetch Operator 
     limit: -1 
     Processor Tree: 
     TableScan 
      alias: t_realtime 
      properties: 
      insideView TRUE 
      GatherStats: false 
      Filter Operator 
      isSamplingPred: false 
      predicate: (active_flag = 1) (type: boolean) 
      Select Operator 
       expressions: cust_id (type: int), name (type: string), status (type: string), 1 (type: int) 
       outputColumnNames: _col0, _col1, _col2, _col3 
       ListSink 

這是在昨天的主線上測試的(在d68630b6ed25884a76030a9073cd864032ab85c2)。如您所見,它只掃描t_realtime並下推謂詞0​​。是否你的特定的安裝會做或不做,這取決於你使用的是什麼版本。本主題受到積極的開發,不僅在Hive上,而且在Calcite(由Hive使用)上。

+0

非常感謝! – Jay

+0

你能否提一下你試過的Hive版本?你是否暗示它在最新的Hive版本分支中的工作正在進行中? – Jay