Hive complex type access operation
Complex type access operation 1. Array type access: a [n]
Syntax: a [n]
Operation type: an is array type, n is int type
Description: returns the nth variable value in array A. The starting subscript of the array is 0. For example, if An is an array type with a value of ['foo',' bar'], then A [0] will return 'foo',' and A [1] will return 'bar''
For example:
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 type access: M [key]
Syntax: M [key]
Operation type: M is the map type, and key is the key value in map
Description: returns the map type M where the key value is the value of the specified value. For example, if M is a map type with a value of {'f'- > 'foo',' bounded-> 'bar',' all'-> 'foobar'}, then M [' all'] will return 'foobar''
For example:
Hive > Create table lxw_test as selectmap ('100th and 2000s) as t from lxw_dual
Hive > select t ['200'], t [' 100'] from lxw_test
Mary tom
3. Struct type access: S.X
Syntax: S.X
Operation type: s is struct type
Description: returns the x field in structure S. For example, for the structure struct foobar {int foo, int bar}, foobar.foo returns the foo field in the structure
For example:
Hive > create table lxw_test as select struct ('tom','mary','tim') as t from lxw_dual
Hive > describe lxw_test
T struct
Hive > select t.col1mt. Col3 from lxw_test
Tom tim
For more exciting content, please follow: http://bbs.superwu.cn
Follow the Superman College Wechat QR code: