欢迎投稿

今日深度:

hive中的数据类型,原始数据jackj

hive中的数据类型,原始数据jackj


数据类型
1.Hive中的数据类型分为两类:基本类型和复杂类型
2.基本类型包含:tinyint,smallint,int,bigint,float,double,boolean,string,timestamp,binary
3.复杂类型:array,map和struct
a. array:数组类型,对应了Java中的集合或者数组。

原始数据
jack,john lucy,mike
tom,bob,cindy lily,helen,mary,alex
frank,grace,iran,eden tony,tone,smith
summy,simon rose,peter,maria

建表
create table battles (groupa array, groupb array) row format delimited fields terminated by ’ ’ collection items terminated by ‘,’;

加载数据
load data local inpath ‘/home/hivedemo/battles’ into table battles;

非空查询
select groupa[2] from battles where groupa[2] is not null;
b. map:映射类型,对应了Java中的Map类型

原始数据
1 tom,19
2 bob,21
3 alex,14
4 peter,17
5 tony,22

建表
create table infos (id int, info map<string, int>) row format delimited fields terminated by ’ ’ map keys terminated by ‘,’;

加载数据
load data local inpath ‘/home/hivedemo/info’ into table infos;

非空查询
select info[‘peter’] from infos where info[‘peter’] is not null;
c. struct:结构体类型。对应了Java中的对象

原始数据
1 adair,19,female,165,58
2 bruce,21,male,185,72
3 cindy,22,female,162,52
4 david,18,male,178,67
5 eden,19,male,182,82
6 frank,20,male,181,71
7 grace,20,female,170,59

建表
create table person(id int, info struct<name:string, age:int, gender:string, height:double, weight:double>) row format delimited fields terminated by ’ ’ collection items terminated by ‘,’;

加载数据
load data local inpath ‘/home/hivedemo/person’ into table person;

获取指定的字段值
select info.name from person;
————————————————
版权声明:本文为CSDN博主「李斌芳」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_49307896/article/details/111330047

www.htsjk.Com true http://www.htsjk.com/hive/45868.html NewsArticle hive中的数据类型,原始数据jackj 数据类型 1.Hive中的数据类型分为两类基本类型和复杂类型 2.基本类型包含tinyintsmallintintbigintfloatdoublebooleanstringtimestampbinary 3.复杂类型arraymap和struct a. a...
评论暂时关闭