[TOC]
# Hive數據類型
## 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訪問元素的方式是通過.符號
- hadoop
- linux基礎
- Linux入門
- Linux進階
- shell
- Zookeeper
- Zookeeper簡介及部署
- Zookeeper使用及API
- Redis
- Redis簡介安裝部署
- Redis使用及API
- Java高級增強
- Java多線程增強
- Maven簡介及搭建
- Hive
- Hive簡介及安裝
- Hive操作
- HIve常用函數
- Hive數據類型
- Flume
- Flume簡介及安裝
- flume 攔截器(interceptor)
- azkaban
- azKaban簡介及安裝
- Sqoop
- Sqoop簡介及安裝
- HDFS
- HDFS原理
- HDFS操作API
- MAPREDUCE原理
- MAPREDUCE圖片資源
- MAPREDUCE加強
- HBASE
- HBASE簡介及安裝
- HBASE操作及API
- HBASE內部原理
- Storm
- Storm簡介及安裝
- Storm原理
- kafka
- kafka簡介及安裝
- kafka常用操作及API
- kafka原理
- kafka配置詳解
- Scala
- Scala簡介及安裝
- Scala基礎語法
- Scala實戰