Hive之 数据类型

hive 目前支持的数据类型如下:

-- 数值类型 Numeric Types
TINYINT (1-byte signed integer, from -128 to 127)
SMALLINT (2-byte signed integer, from -32,768 to 32,767)
INT/INTEGER (4-byte signed integer, from -2,147,483,648 to 2,147,483,647)
BIGINT (8-byte signed integer, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
FLOAT (4-byte single precision floating point number)
DOUBLE (8-byte double precision floating point number)
DOUBLE PRECISION (alias for DOUBLE, only available starting with Hive 2.2.0)
DECIMAL
Introduced in Hive 0.11.0 with a precision of 38 digits
Hive 0.13.0 introduced user-definable precision and scale
NUMERIC (same as DECIMAL, starting with Hive 3.0.0)

--日期/时间类型 Date/Time Types
TIMESTAMP (Note: Only available starting with Hive 0.8.0)
DATE (Note: Only available starting with Hive 0.12.0)
INTERVAL (Note: Only available starting with Hive 1.2.0)

--字符类型 String Types
STRING
VARCHAR (Note: Only available starting with Hive 0.12.0)
CHAR (Note: Only available starting with Hive 0.13.0)

Misc Types
BOOLEAN
BINARY (Note: Only available starting with Hive 0.8.0)

--复杂类型 Complex Types
arrays: ARRAY<data_type> (Note: negative values and non-constant expressions are allowed as of Hive 0.14.)
maps: MAP<primitive_type, data_type> (Note: negative values and non-constant expressions are allowed as of Hive 0.14.)
structs: STRUCT<col_name : data_type [COMMENT col_comment], ...>
union: UNIONTYPE<data_type, data_type, ...> (Note: Only available starting with Hive 0.7.0.)

例子:

1)Array数组
数据类型相同的元素集合。

hive>create table student
(sid int,
sname string,
grade array<float>);
其中array代表各科成绩,比如:
{1,YY,[80,100,90]}

2)Map
key和value对:

hive>create table student2
(sid int,
sname string,
grade map<string,float>);
其中map指的是学科对应的成绩,比如:
{1,yy,<'English',90>}
上面的array和map可以组合起来使用,一个人的各科成绩:

hive> create table student3
(sid int,
sname string,
grades array<map<string,float>>);
{1,'yy',[<'English',80>,<'English2',90>]}

3)struct
结构体:

hive>create table student4
(sid int,
info struct<name:string,age:int,sex:string>);
比如:
{1,{'yy',20,'male'}}

posted on 2017-09-19 19:36  张冲andy  阅读(1153)  评论(0编辑  收藏  举报

导航