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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

hive 复合类型_hive 常用函数整理 9.复合类型操作

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

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 student;

hive> describe lxw_test;

t map

hive> select t from lxw_test;

{"100":"tom","200":"mary"}

--通過key 查詢value

hive> select t['100'] from lxw_test limit 1;

Tom

--查看鍵值對的個數

hive> select size(t) from lxw_test limit 1;

2

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 select map('100','tom','200','mary') as t from student;

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

mary tom

3. map 取出key集合

4. map類型長度函數: size(Map)

語法: size(Map)

返回值: int

說明: 返回map類型的長度

舉例:

hive> select size(map('100','tom','101','mary')) from student;

2

5. array類型構建: array

語法: array(val1, val2, …)

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

舉例:

hive> create table lxw_test as select array("tom","mary","tim") as t from student;

hive> describe lxw_test;

t array

hive> select t from lxw_test;

["tom","mary","tim"]

hive> select t[1] from lxw_test3;

mary

6. 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 select array("tom","mary","tim") as t from student;

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

tom mary tim

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

語法: size(Array)

返回值: int

說明: 返回array類型的長度

舉例:

hive> select size(array('100','101','102','103')) from student;

4

8. struct類型構建: struct

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

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

舉例:

hive> create table lxw_test2 as select struct('tom','mary','tim') as t from student;

hive> describe lxw_test2;

t struct

hive> select t from lxw_test2;

{"col1":"tom","col2":"mary","col3":"tim"}

hive> select t.col1 from lxw_test2;

tom

9. 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 student;

hive> describe lxw_test;

t struct

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

tom tim

10. 類型轉換函數 cast(expr as )

類型轉換函數: cast

語法: cast(expr as )

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

說明: 返回array類型的長度

舉例:

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

1

hive> Create table lxw_test5 as select 1 as t from student;

hive> desc lxw_test5;

t int

hive> Create table lxw_test6 as select cast(1 as bigint) as t from student;

hive> desc lxw_test6;

t bigint

總結

以上是生活随笔為你收集整理的hive 复合类型_hive 常用函数整理 9.复合类型操作的全部內容,希望文章能夠幫你解決所遇到的問題。

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