Hive数据类型-集合类型(Array-Map-Struct)的尝试
来源:互联网 发布:mac怎么局部截图 编辑:程序博客网 时间:2024/06/04 19:32
Hive支持的数据类型分为基础数据类型和集合类型。
基础类型主要包括:tinyint,smalint,int,bigint,boolean,float,double,string,timestamp,ninary等。这些基础类型和其他关系型数据库中的基础数据类型差不多。
集合类型主要包括:array,map,struct等,hive的特性支持集合类型,这特性是关系型数据库所不支持的,利用好集合类型可以有效提升SQL的查询速率。
由于官方文件的实例中没有集合类型的例子,所以就自己尝试了。下面是3种集合类型的简单实现。
ARRAY类型的实现
先建一张表,建表脚本如下:
create table t_person(id int,name string,likes array<string>)row format delimitedfields terminated by ','collection items terminated by '_';新建一个文本文件,格式如下:【这是根据建表时的规格,准备导入表的数据格式】
1,王力宏,唱歌_钢琴_二胡_作曲_演戏_导演_书法
执行导入数据的命令,然后再查询该表就可以看到数据了。
load data local inpath 'Documents/hive/t_person.txt' into table t_person;查询一下试试看:【array的访问元素和java中是一样的,这里通过索引来访问】
select name,likes[1] as likes from t_person;
MAP类型的实现
先建一张表,建表脚本如下:
create table t_person(id int,name string,tedia map<string,string>)row format delimitedfields terminated by ','collection items terminated by '_'map keys terminated by ':';新建一个文本文件,格式如下:【这是根据建表时的规格,准备导入表的数据格式】
1,王力宏,性别:男_形象:非常健康执行导入数据的命令,然后再查询该表就可以看到数据了。
load data local inpath 'Documents/hive/t_person.txt' into table t_person;查询一下试试看:【map访问元素的方式是通过key】
select name,tedia['<span style="font-family: Arial, Helvetica, sans-serif;">性别</span><span style="font-family: Arial, Helvetica, sans-serif;">'] as xb from t_person;</span>
STRUCT类型的实现
先建一张表,建表脚本如下:create table t_person(id int,name string,address struct<city:string,street:string>)row format delimitedfields terminated by ','collection items terminated by '_';新建一个文本文件,格式如下:【这是根据建表时的规格,准备导入表的数据格式】
1,王力宏,台湾省_台北市执行导入数据的命令,然后再查询该表就可以看到数据了。
load data local inpath 'Documents/hive/t_person.txt' into table t_person;查询一下试试看:【struct访问元素的方式是通过.符号】
select name,address.city as city<span style="font-family: Arial, Helvetica, sans-serif;"> from t_person;</span>
0 0
- Hive数据类型-集合类型(Array-Map-Struct)的尝试
- Hive集合数据类型(Struct,Map,Array)
- HIVE的数据类型hive array、map、struct使用
- Hive复合数据类型array,map,struct的使用
- Hive复合数据类型array,map,struct的使用
- hive复合数据类型 array、map、struct使用
- hive struct\map\array
- hive map,struct,array
- Hive 中 Array、Map、Struct 的使用
- hive中map、struct、array的使用
- hive 的ARRAY,MAP,STRUCT使用
- hive的三种复合数据类型array、map、struct以及自定义分割符示例
- Hive学习笔记 --- Array, Map, Struct类型使用
- hive array、map、struct使用
- hive array、map、struct使用
- hive array、map、struct使用
- hive array、map、struct使用
- hive array、map、struct使用
- 在word文档中如何插入Mathtype公式
- cocoapods安装
- Python pandas insert list into a cell
- iOS开发-UI控件:动态改变UITableView中的Cell高度
- CF 653B. Bear and Compressing
- Hive数据类型-集合类型(Array-Map-Struct)的尝试
- Android Studio上 drawable与mipmap的区别
- 红黑树、插入删除操作
- MFC CListCtrl 刷新数据时闪屏解决方法
- 教您如何在Word的mathtype加载项中修改章节号
- Android集成微信支付功能
- Integrating Apache Spark with PyCharm
- HDU 1285 确定比赛名次 【入门拓扑排序】
- Qt生成随机数的方法