直接在 Linux 命令行环境下执行 hive 命令
hive -e “”
[root@hadoop0 ~]# hive -e "create table t1(name string);"
分区表
hive> create table t1(id int) partitioned by (day int);
Hive 把表组织成“分区”(partition)。这是一种根据“分区列”(partition column,如日期)的值对表进行粗略划分的机制。使用分区可以加快数据分片(slice)的查询速度。
(1)分区表的适用场景
每天产生一个文件夹,可根据日期建立分区表,这样就避免了对所有的目录进行全表扫描;
(2)关键字:partitioned by ()
后边小括号跟的内容,作为一个单独的列,为分区列“partition column”,这也是分区的划分依据
分区表的创建流程:
(1) 创建分区表(指定“分区列” partition column)
create external table hmbbs(ip string, atime string, url string) partitioned by (logdate string) row format delimited fields terminated by ‘\t’ location ‘/hmbbs_cleaned’
此时表中未有数据,因为未增加分区
(2)增加分区
alter table hmbbs add partition(logdate=2013_05_30) location ‘/hmbbs_cleaned/2013_05_30’;
外部表
通过外部文件(hdfs 上的文件)的数据信息创建自己的表,关键字:external、location;
hive> create external table t5(id int) location '/external';