Hive 根據時間對 “對話”數據進行排序

由於使用 sort by (order by, distribute by, cluster by 等)對同一個 ID 根據時間進行排序時,並不是按照真正的時間進行排序(sort by , 其實是對每個reduce中對數據進行排序,也就是執行一個局部排序過程)。故使用 sort_array 對數據排序。

示例如下:

select
sessionid,

regexp_replace(
concat_ws('###===###', sort_array(
collect_list(concat_ws('=', cast(time as string), content)
)
)
), '[0-9]{{4}}-[0-9]{{2}}-[0-9]{{2}} [0-9]{{2}}:[0-9]{{2}}:[0-9.]{{2,4}}=', '') as session_seq_text

from

(

select sessionid, content, time from your_self_hive_table 
where dt='2020-06-01' and length(content)>0 and score>=0.5

) x

group by sessionid

;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章