hive的数据类型
2018-03-12 23:04
393 查看
1. hive的数据类型
Hive的内置数据类型可以分为两大类:(1)、基础数据类型;(2)、复杂数据类型2. hive基本数据类型
基础数据类型包括:TINYINT,SMALLINT,INT,BIGINT,BOOLEAN,FLOAT,DOUBLE,STRING,BINARY,TIMESTAMP,DECIMAL,CHAR,VARCHAR,DATE。3. hive集合类型
集合类型主要包括:array,map,struct等,hive的特性支持集合类型,这特性是关系型数据库所不支持的,利用好集合类型可以有效提升SQL的查询速率。3.1 集合类型之array
(1) 先创建一张表create table t_array(id int,name string,hobby array<string>) row format delimited fields terminated by ',' collection items terminated by '-'; |
(2) 准备数据文件 array.txt
1,zhangsan,唱歌-跳舞-游泳 2,lisi,打游戏-篮球 |
(3) 加载数据文件到t_array表中
load data local inpath ‘/root/array.txt’ into table t_array;
(4) 查询数据
select id ,name,hobby[0],hobby[1] from t_array;
注意:array的访问元素和java中是一样的,这里通过索引来访问。
3.2 集合类型之map
(1) 先创建一张表create table t_map(id int,name string,hobby map<string,string>) row format delimited fields terminated by ',' collection items terminated by '-' map keys terminated by ':' ; |
(5) 准备数据文件 map.txt
1,zhangsan,唱歌:非常喜欢-跳舞:喜欢-游泳:一般般 2,lisi,打游戏:非常喜欢-篮球:不喜欢 |
(6) 加载数据文件到t_map表中
load data local inpath ‘/root/map.txt’ into table t_map;
(7) 查询数据
select id,name,hobby['唱歌'] from t_map;
注意:map的访问元素中的value和java中是一样的,这里通过key来访问。
3.3集合类型之struct
(1) 先创建一张表create table t_struct(id int,name string,address struct<country:string,city:string>) row format delimited fields terminated by ',' collection items terminated by '-'; |
(8) 准备数据文件 struct.txt
1,zhangsan,china-beijing 2,lisi,USA-newyork |
(9) 加载数据文件到t_struct表中
load data local inpath ‘/root/struct.txt’ into table t_struct;
(10) 查询数据
select id,name,address.country,address.city from t_struct;
总结:struct访问元素的方式是通过.符号
相关文章推荐
- Hive支持的数据类型
- hive中执行sql语句出现数据类型问题
- Hive笔记-数据类型
- Hive 的内置数据类型
- Hive之数据类型
- Hive数据类型、文件格式和数据定义
- 大数据时代的技术hive:hive的数据类型和数据模型
- hive高级数据类型
- 大数据Spark “蘑菇云”行动第106课:Hive源码大师之路第四步:Hive中GroupBy和各种类型Join源码剖析
- [置顶] 第92课,Hive中的Array,Map,Struct及自定义数据类型案例实战。
- Hive内置数据类型
- Hive 5、Hive 的数据类型 和 DDL Data Definition Language)
- hive[3] 数据类型和文件格式
- 大数据时代的技术hive:hive的数据类型和数据模型
- hive 学习(1) 内置函数以及数据类型
- Hive基础二(join原理和机制,join的几种类型,数据倾斜简单处理)
- hive数据类型(翻译自Hive Wiki)
- hive原生和复合类型的数据载入和使用
- [转]Hive 数据类型
- 大数据时代的技术hive:hive的数据类型和数据模型