說真的,這個模式在我做sql開發的歲月裡,從未用到過。用的都是動態分割槽非嚴格模式。
我的好友東嶽同學在車上問我。確實問到了我 。體現出了我基本功不紮實的情況。
hive提供了乙個嚴格模式,可以防止使用者執行那些可能產生意向不到的不好的效果的查詢。說通俗一點就是這種模式可以阻止某些查詢的執行。通過如下語句設定嚴格模式:
hive>設定為嚴格模式後,可以禁止3種型別的查詢:set hive.mapred.mode=strict;
(1):帶有分割槽的表的查詢
如果在乙個分割槽表執行hive,除非where語句中包含分割槽字段過濾條件來顯示資料範圍,否則不允許執行。換句話說就是在嚴格模式下不允許使用者掃瞄所有的分割槽。
進行這個限制的原因是,通常分割槽表都擁有非常大的資料集,而且資料增加迅速。如果不進行分割槽限制的查詢會消耗巨大的資源來處理,如下不帶分割槽的查詢語句:
hive>執行後會出現如下錯誤:select
distinct(planner_id) from fracture_ins where planner_id=
5;
failed: error in semantic analysis: no partition predicate found for alias "fracture_ins" table "fracture_ins解決方案是在where中增加分割槽條件:
hive>select
distinct(planner_id) from
fracture_ins
>
where planner_id=
5and hit_date=
20120101;
hive>出現如下錯誤:select
*from fracture_ins where hit_date>
2012
order
by planner_id;
failed: error in semantic analysis: line 1:56解決方案就是增加乙個limit關鍵字:instrict mode,limit must be specified
iforder
byis present planner_id
hive>(3):限制笛卡爾積的查詢select
*from fracture_ins where hit_date>
2012
order
byplanner_id limit 100000;
對關係型資料庫非常了解的使用者可能期望在執行join查詢的時候不適用on語句而是使用where語句,這樣關係型資料庫的執行優化器就可以高效的將where語句轉換成那個on語句了。不幸的是,hive並不支援這樣的優化,因為如果表非常大的話,就會出現不可控的情況,如下是不帶on的語句:
hive>出現如下錯誤:select
*from fracture_act join fracture_ads where fracture_act.planner_id = fracture_ads.planner_id;
failed: error in semantic analysis: in*****==》我感覺整個都存在不加思考的抄襲的現象。要不然就是改一改表名,裝作成自己的。連最基礎的概念什麼是笛卡爾積都不知道strict mode, cartesian product
isnot allowed. if you really want to
perform the operation,
+set hive.mapred.mode=nonstrict+
這才是真正的笛卡爾積,上面根本不會報錯。
hive> select * from fracture_act join fracture_ads where 1= 1;或者是
hive> select * from fracture_act join fracture_ads;解決方案就是加上on語句:
hive>或者是加上where條件select
*from fracture_act join fracture_ads on (fracture_act.planner_id = fracture_ads.planner_id);
hive> select * from fracture_act join fracture_ads where fracture_act.planner_id = fracture_ads.planner_id;不過on效能更好一些。
hive 嚴格模式
hive提供了乙個嚴格模式,可以防止使用者執行那些可能產生意向不到的不好的效果的查詢。說通俗一點就是這種模式可以阻止某些查詢的執行。通過如下語句設定嚴格模式 hive set hive.mapred.mode strict hive select distinct planner id from f...
hive嚴格模式
hive嚴格模式 hive提供了乙個嚴格模式,可以防止使用者執行那些可能產生意想不到的不好的效果的查詢。即某些查詢在嚴格 模式下無法執行。1 帶有分割槽的表的查詢 如果在乙個分割槽表執行hive,除非where語句中包含分割槽字段過濾條件來顯示資料範圍,否則不允許執行。換句話說,就是使用者不允許掃瞄...
hive優化 嚴格模式
預設配置為 hive.mapred.mode nonstrict the mode in which the hive operations are being performed.in strict mode,some risky queries are not allowed to run.th...