日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hive常用函数之其他函数

發布時間:2024/3/12 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hive常用函数之其他函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

九、復合類型構建操作

1. Map類型構建: map

語法: map (key1, value1, key2, value2,…)

說明:根據輸入的key和value對構建map類型

舉例:

hive> Create table lxw_test as select map(‘100’,‘tom’,‘200’,‘mary’)as t from lxw_dual;

hive> describe lxw_test;

t map<string,string>

hive> select t from lxw_test;

{“100”:“tom”,“200”:“mary”}

2. Struct類型構建: struct

語法: struct(val1, val2, val3,…)

說明:根據輸入的參數構建結構體struct類型

舉例:

hive> create table lxw_test as select struct(‘tom’,‘mary’,‘tim’)as t from lxw_dual;

hive> describe lxw_test;

t structcol1:string,col2:string,col3:string

hive> select t from lxw_test;

{“col1”:“tom”,“col2”:“mary”,“col3”:“tim”}

3. array類型構建: array

語法: array(val1, val2,…)

說明:根據輸入的參數構建數組array類型

舉例:

hive> create table lxw_test as selectarray(“tom”,“mary”,“tim”) as t from lxw_dual;

hive> describe lxw_test;

t array

hive> select t from lxw_test;

[“tom”,“mary”,“tim”]

十、復雜類型訪問操作

1. array類型訪問: A[n]

語法: A[n]

操作類型: A為array類型,n為int類型

說明:返回數組A中的第n個變量值。數組的起始下標為0。比如,A是個值為[‘foo’, ‘bar’]的數組類型,那么A[0]將返回’foo’,而A[1]將返回’bar’

舉例:

hive> create table lxw_test as selectarray(“tom”,“mary”,“tim”) as t from lxw_dual;

hive> select t[0],t[1],t[2] from lxw_test;

tom mary tim

2. map類型訪問: M[key]

語法: M[key]

操作類型: M為map類型,key為map中的key值

說明:返回map類型M中,key值為指定值的value值。比如,M是值為{‘f’ -> ‘foo’, ‘b’-> ‘bar’, ‘all’ -> ‘foobar’}的map類型,那么M[‘all’]將會返回’foobar’

舉例:

hive> Create table lxw_test as selectmap(‘100’,‘tom’,‘200’,‘mary’) as t from lxw_dual;

hive> select t[‘200’],t[‘100’] from lxw_test;

mary tom

3. struct類型訪問: S.x

語法: S.x

操作類型: S為struct類型

說明:返回結構體S中的x字段。比如,對于結構體struct foobar {int foo, int bar},foobar.foo返回結構體中的foo字段

舉例:

hive> create table lxw_test as select struct(‘tom’,‘mary’,‘tim’)as t from lxw_dual;

hive> describe lxw_test;

t structcol1:string,col2:string,col3:string

hive> select t.col1,t.col3 from lxw_test;

tom tim

十一、復雜類型長度統計函數

1. Map類型長度函數: size(Map<K.V>)

語法: size(Map<K.V>)

返回值: int

說明:返回map類型的長度

舉例:

hive> select size(map(‘100’,‘tom’,‘101’,‘mary’)) from lxw_dual;

2

2. array類型長度函數: size(Array)

語法: size(Array)

返回值: int

說明:返回array類型的長度

舉例:

hive> select size(array(‘100’,‘101’,‘102’,‘103’)) from lxw_dual;

4

3. 類型轉換函數

類型轉換函數: cast

語法: cast(expr as )

返回值: Expected “=” to follow “type”

說明:返回array類型的長度

舉例:

hive> select cast(1 as bigint) from lxw_dual;

1

總結

以上是生活随笔為你收集整理的hive常用函数之其他函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。