hive 高級結構

•array類型訪問: A[n]
•map類型訪問: M[key]
•struct類型訪問: S.x
• array 類型訪問 : A[n]
語法: A[n]
操作類型: A爲array類型,n爲int類型
說明:返回數組A中的第n個變量值。數組的起始下標爲0。比如,A是個值爲['foo', 'bar']的數組類型,那麼A[0]將返回'foo',而A[1]將返回'bar'
舉例:
hive> create table alex_test as select array("tom","mary","tim") as t from dual;
hive> select t[0],t[1],t[2] from alex_test;
tom     mary    tim
• 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 alex_test as select map('100','tom','200','mary') as t from dual;
hive> select t['200'],t['100'] from alex_test;
mary    tom
• struct 類型訪問 : S.x
語法: S.x
操作類型: S爲struct類型
說明:返回結構體S中的x字段。比如,對於結構體struct foobar {int foo, int bar},foobar.foo返回結構體中的foo字段
舉例:
hive> create table alex_test as select struct('tom','mary','tim') as t from dual;
hive> describe alex_test;
t       struct<col1:string,col2:string,col3:string>
hive> select t.col1,t.col3 from alex_test;
tom     tim
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章