总目录:https://www.jianshu.com/p/e406a9bc93a9
Hadoop - 子目录:https://www.jianshu.com/p/9428e443b7fd
基本数据类型
数据类型表:
HIVE数据类型 | JAVA数据类型 | 长度 | 例子 |
---|---|---|---|
TINYINT | byte | 1byte有符号整数 | 20 |
SMALINT | short | 2byte有符号整数 | 20 |
INT | int | 4byte有符号整数 | 20 |
BIGINT | long | 8byte有符号整数 | 20 |
BOOLEAM | booleam | 布尔类型 | TRUE |
FLOAT | float | 单精度浮点数 | 1.2 |
DOUBLE | double | 双精度浮点数 | 1.2 |
STRING | string | 字符串 | "hello bigdata" |
TIMESTAMP | 时间类型 | ||
BINARY | 字符数组 |
集合数据类型
数据类型 | 描述 | 语法示例 |
---|---|---|
STRUCT | 结构体,通过点操作符访问元素。 | struct() |
MAP | 字典,是一个K-V的元组结合。 | map() |
ARRAY | 数组,一组相同类型的元素的集合。 | array() |
然后看一下集合数据类型的例子:
建表
hive (default)> create table test(
> name string,
> friends array<string>,
> children map<string,int>,
> address struct<street:string,city:string>
> )
> row format delimited
> fields terminated by ','
> collection items terminated by '_'
> map keys terminated by ':'
> lines terminated by '\n';
OK
Time taken: 1.699 seconds
row format delimited fields terminated by ','
-- 列分隔符
collection items terminated by '_'
-- 数据类型分隔符
map keys terminated by ':'
-- map中k-v的分隔符
lines terminated by '\n'
--行分隔符
准备数据:
json格式:
{
"name":"zhangsan",
"friends":["lisi","wangwu"],
"children":{
"xiaozhang":19,
"xiaosan":20
}
"address":{
"street":"beisong",
"city":"shijiazhuang"
}
}
文件格式:
zhangsan,lisi_wangwu,xiaozhang:19_xiaosan:20,beisong_shijiazhuang
xiaoming,xiaohong_xiaogang,xiaoxiao:19_xiaoxiaoming:20,zhongmei_shijiazhuang
字段之间使用,
分割,map数据类型的K-V使用:
分割,同一种类型的不同元素使用_
分割,每一行数据使用\n
分割。
导入
load data local inpath '/usr/test1.txt' into table test;
![](https://img.haomeiwen.com/i20155953/b1432d2cc94f998c.png)
查询
![](https://img.haomeiwen.com/i20155953/40405c707f08969e.png)
map数据类型可以指定key查询。
![](https://img.haomeiwen.com/i20155953/dd56d897585f0fbc.png)
struct数据类型使用
.
操作符![](https://img.haomeiwen.com/i20155953/9278b5df445f9eac.png)
网友评论