ARRAY

一组有序字段,字段的类型必须相同。Array(1,2)

create table hive_array(ip string, uid array<string>)
row format delimited
fields terminated by ','
collection items terminated by '|'
stored as textfile;

加载数据

load data local inpath "/home/spark/software/data/hive_array.txt" overwrite into table hive_array;

hive_array.txt

192.168.1.1,www.baidu.com|www.google.com|www.qq.com
192.168.1.2,www.baidu.com|www.sina.com|www.sohu.com
192.168.1.3,www.qq.com|www.163.com|www.youku.com
select * from hive_array;
192.168.1.1 ["www.baidu.com","www.google.com","www.qq.com"]
192.168.1.2 ["www.baidu.com","www.sina.com","www.sohu.com"]
192.168.1.3 ["www.qq.com","www.163.com","www.youku.com"]

使用下标访问,下标从0开始:

select ip, uid[] as id from hive_array;
192.168.1.1 www.baidu.com
192.168.1.2 www.baidu.com
192.168.1.3 www.qq.com

查看数据长度:

select size(uid) from hive_array;
3
3
3

数组查找:

select * from hive_array where array_contains(uid, "www.baidu.com");
192.168.1.1 ["www.baidu.com","www.google.com","www.qq.com"]
192.168.1.2 ["www.baidu.com","www.sina.com","www.sohu.com"]

MAP

一组无序的键值对,键的类型必须是原子的,值可以是任何类型,同一个映射的键的类型必须相同,值的类型也必须相同。Map('a',1,'b',2)

create table hive_map(ts string, ip string, type string, logtype string, request Map<string,string>, response Map<string, string>)
row format delimited fields terminated by '#'
collection items terminated by '&'
map keys terminated by '='
stored as textfile;

hive_map.txt

2014-03-03 12:22:34#127.0.0.1#get#amap#src=123&code=456&cookie=789#status=success&time=2s
2014-03-03 11:22:34#127.0.0.1#get#autonavi#src=123&code=456#status=success&time=2s&cookie=789

加载数据:

load data local inpath "/home/spark/software/data/hive_map.txt" overwrite into table hive_map;

查看表结构: desc hive_map

ts                      string                  None
ip string None
type string None
logtype string None
request map<string,string> None
response map<string,string> None

查看所有字段:

select * from hive_map;

2014-03-03 12:22:34     127.0.0.1       get     amap    {"src":"123","code":"456","cookie":"789"}       {"status":"success","time":"2s"}
2014-03-03 11:22:34 127.0.0.1 get autonavi {"src":"123","code":"456"} {"status":"success","time":"2s","cookie":"789"}

查看map中指定的字段:

select request['src'], request['code'], request['cookie'] from hive_map;

123     456     789
123 456 NULL

STRUCT

一组命名的字段,字段类型可以不同。 Struct('a',1,2,0)

create table hive_struct(ip string, user struct<name:string, age:int>)
row format delimited fields terminated by '#'
collection items terminated by ':'
stored as textfile;

hive_struct.txt

192.168.1.1#zhangsan:40
192.168.1.2#lisi:50
192.168.1.3#wangwu:60
192.168.1.4#zhaoliu:70

加载数据:

load data local inpath "/home/spark/software/data/hive_struct.txt" overwrite into table hive_struct;

查询所有字段:

select * from hive_struct;

192.168.1.1     {"name":"zhangsan","age":40}
192.168.1.2 {"name":"lisi","age":50}
192.168.1.3 {"name":"wangwu","age":60}
192.168.1.4 {"name":"zhaoliu","age":70}

查询指定字段:

select user.name, user.age from hive_struct;

zhangsan        40
lisi 50
wangwu 60
zhaoliu 70

Hive基础之Hive的复杂类型的更多相关文章

  1. Hive基础之Hive数据类型

    Hive数据类型 参考:中文博客:http://www.cnblogs.com/ggjucheng/archive/2013/01/03/2843448.html          英文:https: ...

  2. Hive基础之Hive体系架构&运行模式&Hive与关系型数据的区别

    Hive架构 1)用户接口: CLI(hive shell):命令行工具:启动方式:hive 或者 hive --service cli ThriftServer:通过Thrift对外提供服务,默认端 ...

  3. Hive基础之Hive环境搭建

    Hive默认元数据信息存储在Derby里,Derby内置的关系型数据库.单Session的(只支持单客户端连接,两个客户端连接过去会报错): Hive支持将元数据存储在关系型数据库中,比如:Mysql ...

  4. Hive基础之Hive的存储类型

    Hive常用的存储类型有: 1.TextFile: Hive默认的存储类型:文件大占用空间大,未压缩,查询慢: 2.Sequence File:将属于以<KEY,VALUE>的形式序列化到 ...

  5. Hive基础之Hive开启查询列名及行转列显示

    Hive默认情况下查询结果里面是只显示值: hive> select * from click_log; OK ad_101 :: ad_102 :: ad_103 :: ad_104 :: a ...

  6. Hive基础之Hive与关系型数据库的比较

    Hive与关系型数据库的比较     使用Hive的CTL(命令行接口)时,你会感觉它很像是在操作关系型数据库,但是实际上,Hive和关系型数据库有很大的不同.       1)Hive和关系型数据库 ...

  7. Hive基础之Hive表常用操作

    本案例使用的数据均来源于Oracle自带的emp和dept表 创建表 语法: CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name ...

  8. Hive基础之Hive是什么以及使用场景

    Hive是什么1)Hive由facebook开源,构建在Hadoop (HDFS/MR)上的用于管理和查询结果化/非结构化的数据仓库:2)一种可以存储.查询和分析存储在Hadoop 中的大规模数据的机 ...

  9. Hive基础(1)

    Hive基础(1) Hive的HQL(2) 1. Hive并不是分布式的,它独立于机器之外,类似于Hadoop的客户端. 2. 元数据和数据的区别,前者如表名.列名.字段名等. 3. Hive的三种安 ...

随机推荐

  1. 关于epoll的IO模型是同步异步的一次纠结过程

    这篇文章的结论就是epoll属于同步非阻塞模型,这个东西貌似目前还是有争议,在新的2.6内核之后,epoll应该属于异步io的范围了,golang的高并发特性就是底层封装了epoll模型的函数,但也有 ...

  2. arcgis-tomcat-cors

    C:\Program Files\ArcGIS\Server\framework\runtime\tomcat\webapps\arcgis#rest\WEB-INF\ (1)添加cors-filte ...

  3. 从 0 到 1 合理高效使用 GitHub 的资料

    来自:https://github.com/xirong/my-git/blob/master/how-to-use-github.md 说明 作为一名开发者,Github上面有很多东西值得关注学习, ...

  4. FZU OJ:2230 翻翻棋

    Problem 2230 翻翻棋 Accept: 872    Submit: 2132Time Limit: 1000 mSec    Memory Limit : 32768 KB  Proble ...

  5. Linux操作系统网络配置

  6. Linq 增删改查

    数据库访问技术: ADO.net EF框架 LinQ LinQ是一种高集成化的数据库访问技术,他将数据库中的表映射成程序中的类 数据库的表名变成类名 数据库的列名变成字段名/属性名 所有的操作都是通过 ...

  7. Restrictions用法

    HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <>  Restrictions.ne() 不等于not equal >  Restrict ...

  8. 【java规则引擎】《Drools7.0.0.Final规则引擎教程》第4章 4.3 定时器

    定时器 规则用基于 interval(间隔)和cron的定时器(timer),替代了被标注过时的duration 属性.timer属性的使用示例: timer ( int: <initial d ...

  9. matplotlib的颜色及线条控制

    refer to: https://www.cnblogs.com/darkknightzh/p/6117528.html

  10. 表单添加缩略图及截图js代码

    此为表单提交是上传截图的代码,待优化: // 添加小程序图片 function addAvatar(obj){ var file = obj.files[0]; limit($('.avatar_bo ...