偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

HIVE中關(guān)于collect_set與explode函數(shù)妙用

大數(shù)據(jù)
Hive中的列支持使用三類復(fù)雜的集合數(shù)據(jù)類型,即:array,map及struct。

[[190170]]

hive的復(fù)合數(shù)據(jù)類型

Hive中的列支持使用三類復(fù)雜的集合數(shù)據(jù)類型,即:array,map及struct,這些類型的名稱是保留字,具體用法可參見該篇博文,里面有關(guān)于三類基本集合數(shù)據(jù)類型的操作實(shí)例,注:map中可嵌套array類型。

例如,定義表:

  1. create table example ( 
  2.     device_id string, 
  3.     login_ip array<string>, 
  4.     user_info map<string,array<string>> 
  5.     address struct<street:string,city:string,state:string> 
  6. row format delimited 
  7. fields terminated by '\001' 
  8. collection items terminated by '\002' 
  9. map keys terminated by '\003' 
  10. lines terminated by '\n' 
  11. stored as RCFile; 

假設(shè)這樣的數(shù)據(jù)類型以分區(qū)表存儲,你要統(tǒng)計(jì)一段時間類no=1下的去重score,那么該怎么辦了?這里可配合使用lateral view首先實(shí)現(xiàn)列轉(zhuǎn)行的功能,如下所示:

select no,score from tablaa lateral view explode(score_set) xxx as score;

注:xxx代表虛表名稱,不能缺少。

進(jìn)一步深化上述代碼解決統(tǒng)計(jì)一段時間的去重值,可寫為:

select no,collect_set(score) from tablaa lateral view explode(score_set) xxx as score group by no;

這樣,將兩個函數(shù)結(jié)合實(shí)現(xiàn)了行轉(zhuǎn)列或列轉(zhuǎn)行的妙用。

責(zé)任編輯:武曉燕 來源: 數(shù)據(jù)之王
相關(guān)推薦

2009-11-26 19:18:59

PHP函數(shù)implod

2024-05-28 12:25:33

Pythonglobals?函數(shù)

2021-03-05 08:31:50

SQLHive語法

2010-10-25 12:05:40

SYS_CONNECT

2011-07-20 17:54:02

C++

2009-11-26 19:05:04

PHP函數(shù)explod

2024-04-25 08:22:43

AndroidlargeHeap屬性

2010-09-10 15:16:51

CSSdisplay

2022-02-17 20:34:12

Python短路機(jī)制開發(fā)

2018-11-13 12:52:50

Linux內(nèi)核棧回溯

2025-05-12 08:50:00

apply()Pandas函數(shù)

2025-02-27 08:13:25

Spring代碼屬性

2010-09-08 15:16:46

clearCSS

2010-09-09 16:54:05

CSSclear

2024-12-19 09:00:00

字典視圖對象Python

2011-08-23 16:22:45

Lua 4.0函數(shù)

2011-08-23 15:02:59

LuaTable

2023-05-22 10:40:22

WeakMapsMaps

2009-08-27 15:22:27

C#中的GET與SET

2009-11-25 16:55:45

PHP函數(shù)explod
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號