基本数据类型

复杂数据类型
- 数组类型 array
- 原始数据:
100,200,300 tom,jary
200,300,500 rose,jack- create external table person(vals array,info2 array) row format delimited fields terminated by’ ’ conllection items teminated by’,’
location ‘/personn’; - 查询每行的个数,select size(vals) from ex;

- create external table person(vals array,info2 array) row format delimited fields terminated by’ ’ conllection items teminated by’,’
- *map类型
- 原始数据:
tom 192.168.234.21
rose 192.168.234.21
tom 192.168.234.22 - 建表语句:
- create external table ex(vals map<string,string>) row format delimited fields terminated by '\t ’ map keys terminated by ’ ’
location ‘/ex’;
注意: map类型的分隔符必须是 \t
- create external table ex(vals map<string,string>) row format delimited fields terminated by '\t ’ map keys terminated by ’ ’
- 查询语句:
- select vals[‘tom’] from ex where vals[‘tom’] is not null;
- select distinct(ip) from (select vals[‘tom’] ip from ex from ex where vals[‘tom’] is not null ) ex1 ;
- struct类型—结构体类型
- 原始数据:
tom 23
rose 22
jary 26 - 建表语句create external table ex(vals struct<name:string,age int>) row format delimited conllection items by ’ ’
location ‘/ex’; - select vals.age from ex where vals.name=‘tom’;
- 原始数据:
本文详细介绍了Hive中各种数据类型的应用,包括基本数据类型、复杂数据类型如数组、map和struct。通过实例展示了如何使用这些数据类型创建外部表,并进行数据查询,如查询数组大小、map中特定键的值等。
2855

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



