一、Hive中的数据类型
基本数据类型:

复杂数据类型:
数组:array
映射:map
对象:struct
1)array
array类型是由一系列相同数据类型的元素组成,这些元素可以通过下标来访问。arr[0]代表第一个元素。
[例]
id name hobby
1 zs eat, sleep
2 ls eat, sleep, run
3 ww study, fly
建表:
create table person(id int, name string, hobby array<string>) row format delimited
fields terminated by '\t' collection items terminated by ','
查询:
select id, name, hobby[1] from person
2)map
MAP 包含 key->value 键值对,可以通过 key 来访问元素。
[例]
id name score
1 zs math:70, English:44
2 ls math:26, computer:74
3 ww computer:13
建表:
create table student(id int, name string, score map<string, int>) row format delimited
fields terminated by '\t' collection items terminated by ',' map keys terminated by ':'
查询:
select id, map['math'] from student
指定分隔符:从外向内依次指定(字段、map中的元素、每个元素的kv)
3)struct
STRUCT 可以包含不同数据类型的元素。可以通过”点语法”的方式来得到所需要的元素。
[例]

本文详细介绍了Hive中的数据类型,包括基本数据类型和复杂数据类型如array、map、struct的使用。此外,还讲解了内置函数的运用,如集合函数、字符串操作、JSON解析等。同时,探讨了如何处理多字节分隔符的问题,并介绍了分析函数(row_number、rank、dense_rank)以及窗口函数的应用,展示了如何在Hive中进行数据聚合和排序分析。
最低0.47元/天 解锁文章
2149

被折叠的 条评论
为什么被折叠?



