赞
踩
Hive 支持多种数据类型,分为原始数据类型和复杂数据类型两类。以下是 Hive 支持的数据类型:
1.整数类型:
tinyint: 1字节有符号整数
smallint: 2字节有符号整数
int: 4字节有符号整数
bigint: 8字节有符号整数
float: 4字节单精度浮点数
double: 8字节双精度浮点数
decimal: 高精度数字类型,可以指定精度和标度,例如 decimal(10,2)
字节(Byte):计算机中最基本的存储单元之一,1字节占8位(bit) ,数据范围:负数范围: -128 到 -1,正数范围: 0 到 127
2.字符串类型:
string: 可变长度字符串
varchar: 具有最大长度限制的可变长度字符串,例如 varchar(255)
char: 固定长度字符串,例如 char(10)
3.日期/时间类型:
timestamp: 包含日期和时间的时间戳,精确到纳秒
date: 仅包含日期部分,不包含时间部分
interval: 时间间隔,用于表示两个日期或时间之间的差值
4.Boolean类型:
boolean: 布尔值,取值为 true 或 false
5.二进制类型:
binary: 任意长度的字节数组
array<T>: 包含多个相同类型元素的有序列表,例如 array<int>
map<K, V>: 键值对的无序集合,其中键和值可以是任意数据类型,例如 map<string, int>
struct<col1: type1, col2: type2, ...>: 包含多个字段的记录,每个字段可以是不同的数据类型,例如 struct<name: string, age: int>
- CREATE TABLE example_table (
- tinyint_col tinyint,
- smallint_col smallint,
- int_col int,
- bigint_col bigint,
- float_col float,
- double_col double,
- decimal_col decimal(10, 2),
- string_col string,
- varchar_col varchar(255),
- char_col char(10),
- timestamp_col timestamp,
- date_col date,
- boolean_col boolean,
- binary_col binary,
- array_col array<int>,
- map_col map<string, int>,
- struct_col struct<name: string, age: int>,
- union_col uniontype<int, string>
- );

hive的存储格式分为两大类:
一类纯文本文件:textfile,不压缩,也是hive的默认存储格式
一类是二进制文件存储:
sequencefile:会压缩,不能使用load方式加载数据
orcfile:会压缩,不能使用load方式加载数据
parquet:会压缩,不能使用load方式加载数据
rcfile:会压缩,不能使用load方式加载数据,是orcfile的低配
textfile和sequencefile的存储格式都是基于行存储的;orc和parquet是基于列式存储的,rcfile是行列混合存储。
在创建表格的时候可以使用stored as parquet指定表格的存储格式,例:
- create table if not exists stocks_parquet (
- track_time string,
- url string,
- session_id string,
- referer string,
- ip string,
- end_user_id string,
- city_id string
- )
- stored as parquet;
修改hive的默认存储格式:
- <property>
- <name>hive.default.fileformat</name>
- <value>TextFile</value>
- <description>
- Expects one of [textfile, sequencefile, rcfile, orc].
- Default file format for CREATE TABLE statement. Users can explicitly override it by CREATE TABLE ... STORED AS [FORMAT]
- </description>
- </property>
- 也可以使用set方式修改:
- set hive.default.fileformat=TextFile
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。