8.2.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 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    struct<col1: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 select array("tom","mary","tim") as t from lxw_dual;

hive> describe lxw_test;
t    array<string>

hive> select t from lxw_test;
["tom","mary","tim"]
Copyright © lucene.xin 2020 all right reserved修改时间: 2021-07-02 11:42:23

results matching ""

    No results matching ""