hadoop Eco --Hive - data type of Hive

A digital type

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) 

Example:

create table t_test(a string ,b int,c bigint,d float,e double,f tinyint,g smallint)

Second, the date and time type

TIMESTAMP (Note: Only available starting with Hive 0.8.0)

DATE (Note: Only available starting with Hive 0.12.0)

Example, if the file has the following data:

. 1 , zhangsan, 1985 - 06 - 30 
2 , Lisi, 1986 - 07 - 10 
. 3 , wangwu, 1985 - 08 - 09

So, you can build a table of data to map

create table t_customer(id int,name string,birthday date)

row format delimited fields terminated by ',';

Then import data

load data local inpath '/root/customer.dat' into table t_customer;

Then, you can query correctly

Third, the string type

STRING

VARCHAR (Note: Only available starting with Hive 0.12.0)

CHAR (Note: Only available starting with Hive 0.13.0)

Fourth, the hybrid type

BOOLEAN

BINARY (Note: Only available starting with Hive 0.8.0)

Fifth, the composite type

5-1 array array type

arrays: ARRAY<data_type> (Note: negative values and non-constant expressions are allowed as of Hive 0.14.)

Example: array type of application

If the following data is needed hive demapping table:

Wolf 2, Wu Jing: Wu Gang: Dragon Mother, 2017 - 08 - 16 
Sansei III miles peach, Liu Yifei: itch, 2017 - 08 - 20

Idea: If the information is starred in an array to map more convenient

Built table:

create table t_movie(moive_name string,actors array<string>,first_show date)

row format delimited fields terminated by ','

collection items terminated by ':';

Import Data:

load data local inpath '/root/movie.dat' into table t_movie;

Inquire:

select * from t_movie;

select moive_name,actors[0] from t_movie;

select moive_name,actors from t_movie where array_contains(actors,'吴刚');

select moive_name,size(actors) from t_movie;

5-2 map type

maps: MAP<primitive_type, data_type> (Note: negative values and non-constant expressions are allowed as of Hive 0.14.)

Example:

. 1 , zhangsan, Father: Xiaoming # Mother: xiaohuang # Brother: Xiaoxu, 28 
2 , Lisi, Father: mayun # Mother: huangyi # Brother: Guanyu, 22 is 
. 3 , wangwu, Father: wangjianlin # Mother: Inner Feeling # SISTER: Jingtian, 29 
4 , mayun, Father: Mother mayongzhen #: Angelababy, 26

Can be described in a family member with said data type of a map 

Construction of the table statement:

create table t_person(id int,name string,family_members map<string,string>,age int)

row format delimited fields terminated by ','

collection items terminated by '#'

map keys terminated by ':';

Inquire:

select * from t_person;

## takes the value of the specified key field map

select id,name,family_members['father'] as father from t_person;

Take ## map all key fields

select id,name,map_keys(family_members) as relation from t_person;

## take all the value of a field map

select id,name,map_values(family_members) from t_person;

select id,name,map_values(family_members)[0] from t_person;

Comprehensive ##: user information query has a brother

select id,name,father
from
(select id,name,family_members['brother'] as father from t_person) tmp
where father is not null;

5-3 struct type 

structs: STRUCT<col_name : data_type, ...>

Examples

1, zhangsan, 18: male: beijing

2, lisi, 28: female: shanghai

 

Which contain user information: Age: integer, gender: string, address: String

Envisions a field to describe the entire user information, may be employed struct

Built table:

create table t_person_struct(id int,name string,info struct<age:int,sex:string,addr:string>)

row format delimited fields terminated by ','

collection items terminated by ':';

Inquire

select * from t_person_struct;

select id,name,info.age from t_person_struct;

 

Guess you like

Origin www.cnblogs.com/Jing-Wang/p/10945443.html