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. Xcode清理垃圾

    摘抄自https://blog.csdn.net/hu434587115/article/details/54602449 ~/Library/Developer/Xcode/DerivedData/ ...

  2. 6.1 socket 长连接、短连接

    一般情况下,服务器的长连接和短连接不是服务器说了算,而是客户端说了算.因为服务器是给别人提供业务的,一旦连接建立起来之后,服务器端不会主动把连接给close掉. 客户端发送一笔业务,没有关闭连接,然后 ...

  3. 5.1 socket编程、简单并发服务器

    什么是socket? socket可以看成是用户进程与内核网络协议栈的编程接口.是一套api函数. socket不仅可以用于本机的进程间通信,还可以用于网络上不同主机间的进程间通信. 工业上使用的为t ...

  4. SQL 基础--> NEW_VALUE 的使用

    --=============================== -- SQL 基础--> NEW_VALUE 的使用 --=============================== 通常 ...

  5. [Data Structure] Linked List Implementation in Python

    class Empty(Exception): pass class Linklist: class _Node: # Nonpublic class for storing a linked nod ...

  6. Unity 3D游戏-塔防类游戏源码:重要方法和功能的实现

    Unity-塔防游戏源码 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 1 2 3 4 5 6 7 8 9 ...

  7. HDU 1114:Piggy-Bank(完全背包)

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  8. ZZNU 2125:A + B 普拉斯(傻逼题+大数加法)

    2125: A + B 普拉斯 时间限制: 1 Sec  内存限制: 128 MB 提交: 94  解决: 28 [提交] [状态] [讨论版] [命题人:admin] 题目描述 "别人总说 ...

  9. How Many Tables 简单并查集

    Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to kn ...

  10. (2)socket的基础使用(基于TCP协议)

    socket()模块函数用法 基于TCP协议的套接字程序 netstart -an | findstr 8080 #查看所有TCP和UDP协议的状态,用findstr进行过滤监听8080端口 服务端套 ...