Hive(21):Hive数据类型

1.Hive数据类型

  数值型:tinyint、smallint、int、bigint
  字符型:varchar、char、string
  时间型:date、timestamp
  其他类型:boolean
  复杂类型:arrays(下标是从0开始)、map(key,value)、structs
     userlist map(int,string)    userlist['1']取出value
     user structs<name:string,age:int>  user.name  user.age

2.实例

(1)创建表

CREATE TABLE if not exists `jihetable`(                        
  `id` string,
  `area` array<string>,
  `province` map<int,string>,
  `city` struct<name:string,city:string,type:int>)
ROW FORMAT DELIMITED
  FIELDS TERMINATED BY '\t'
  COLLECTION ITEMS TERMINATED BY ','
  MAP KEYS TERMINATED BY ':'
  LINES TERMINATED BY '\n'
STORED AS textfile;

(2)数据

    A    华东,华南,华北    1:北京,2:天津,2:天津    南京,A23,2
    B    华东,西南,华北    3:北京,2:天津,2:天津    福州,A23,2
    C    华东,华南,中原    5:宁夏,2:河南,2:天津    上海,A1,2

(3)加载数据load

load data local inpath '/opt/datas/jihetest' into table jihetable;

(4)查看

select * from jihetable;

结果:
+---------------+-------------------+---------------------+-------------------------------------------+--+
| jihetable.id  |  jihetable.area   | jihetable.province  |              jihetable.city               |
+---------------+-------------------+---------------------+-------------------------------------------+--+
| A             | ["华东,华南,华北"]      | {}                  | {"name":"南京,A23","city":"3","type":null}  |
| B             | ["华东,语文,属性"]      | {}                  | {"name":"上海,A23","city":"3","type":null}  |
| A             | ["华东","华南","华北"]  | {1:"北京",2:"天津"}     | {"name":"南京","city":"A23","type":2}       |
| B             | ["华东","西南","华北"]  | {3:"北京",2:"天津"}     | {"name":"福州","city":"A23","type":2}       |
| C             | ["华东","华南","中原"]  | {5:"宁夏",2:"河南"}     | {"name":"上海","city":"A1","type":2}        |
+---------------+-------------------+---------------------+-------------------------------------------+--+

猜你喜欢

转载自blog.csdn.net/u010886217/article/details/83926453