本文共 1573 字,大约阅读时间需要 5 分钟。
Hive中的基本数据类型类似于数据库中的基本数据类型,支持整数、浮点数、字符串等多种类型。以下是几种常用的基本数据类型的特点:
Hive支持三种复杂数据类型:ARRAY、MAP和STRUCT。这些数据类型允许数据的嵌套和分层,适用于存储结构化数据:
以下是一个复杂数据结构的示例:
{ "name": "songsong", "friends": ["bingbing", "lili"], "children": { "xiao song": 18, "xiaoxiao song": 19 }, "address": { "street": "hui long guan", "city": "beijing" } } 在Hive中访问上述数据结构的方式如下:
{ "name": "songsong", "friends": ["bingbing", "lili"], "children": { "xiao song": 18, "xiaoxiao song": 19 }, "address": { "street": "hui long guan", "city": "beijing" } } 创建对应表格的SQL语句如下:
create table test( name string, friends array, children map, address struct ) row format delimited fields terminated by ',' collection items terminated by '_' map keys terminated by ':' lines terminated by '\n';
导入数据的命令为:
load data local inpath ‘/opt/module/datas/test.txt’ into table test;
访问集合类型数据的方式如下:
select friends[1], children['xiao song'], address.city from test where name="songsong";
返回结果为:
lili 18 beijing
Hive支持隐式和显式类型转换,以下是类型转换的规则:
转载地址:http://lzeq.baihongyu.com/