1. 程式人生 > >每天學習筆記系列-HIVE SQL : ORDER BY 與 SORT BY

每天學習筆記系列-HIVE SQL : ORDER BY 與 SORT BY

之前一直沒太關注 order by 和sort by的區別,今天看了下。

首先 ,如果在 嚴格模式下直接使用order by 會報錯,必須加上 LIMIT關鍵字;

 In strict mode, if ORDER BY is specified, LIMIT must also be specified.
set hive.mapred.mode=nonstrict;  #或者將引數值設定為,nostrict
select 
*
from 
A
where d ='2018-10-22'
order by checkin_time 
limit 100

sort  by 的語法不會受到set hive.mapred.mode 引數影響,
 

select 
*
from 
A
where d ='2018-10-22' 
sort by checkin_time 

 distribute  by  $   按指定的key 去分發資料,相同key資料會被分到同一個reduce

select 
*
from 
A
where d ='2018-10-22'
distribute by clientname  
sort by checkin_time 


#cluster by 等價於以上語句,但是cluster by 只能降序


select 
*
from 
ods_corp_chtlorderdb.Ord_Corp_HotelClient_Info
where d ='2018-10-22' 
cluster by checkin_time