Hive之 資料型別

張衝andy發表於2017-09-19

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'}}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31383567/viewspace-2145188/,如需轉載,請註明出處,否則將追究法律責任。

相關文章