走进大数据之Hive入门2

2016-09-21  本文已影响0人  Derrick_Xu

一、Hive数据类型

1.基本数据类型

2.复杂数据类型

creat table student
(sid int, sname string, grade array<float>);
{1,Tom,[80,90,75]}

creat table student1
(sid int, sname string, grade map<string, float>);
{1,Tom,<'语文',85>}

array和map的嵌套使用
creat table student2
(sid int, sname string, grades array<map<string,float>>);
{1,Tom, [<'语文',80>,<'英语',90>]}

creat table student3
(sid int, info struct<name:string, age:int, sex:string>);

3.时间类型

select unix_timestamp

二、Hive的数据存储

当我们在Hive中创建了一张表,就相当于在HDFS中创建了一个文件夹,而表中的数据就相当于文件夹中的文件。

内部表 创建内部表

creat table student
(sid int, sname string, age int)
location '/mytable/hive/student';
row formats delimited fields terminated by ',';

分区表

creat table partition_table
(sid int, sname string)
partitioned by (gender string)
row format delimited fields terminated by ',';
insert into partition_table partition(gender='M') select sid,sname from sample_data where gender='M';

外部表
上一篇 下一篇

猜你喜欢

热点阅读