标签:hive
HIVE的分区通过在创建表时启用partitionby实现,用来partition的维度并不是实际数据的某一列,具体分区的标志是由插入内容时给定的。当要查询某一分区的内容时可以采用where语句,形似where
tablename.partition_key >a来实现。
创建含分区的表。
命令原型:
CREATE TABLE page_view(viewTime INT, userid BIGINT,
page_urlSTRING, referrer_url STRING,
ip STRINGCOMMENT ‘IP Address of the User‘)
COMMENT ‘This isthe page view table‘
PARTITIONED BY(dtSTRING, country STRING)
CLUSTEREDBY(userid) SORTED BY(viewTime) INTO 32 BUCKETS
ROW FORMATDELIMITED
FIELDSTERMINATED BY ‘\001‘
COLLECTION ITEMSTERMINATED BY ‘\002‘
MAP KEYSTERMINATED BY ‘\003‘
STORED ASSEQUENCEFILE;
Eg:
建表:
CREATE TABLE c02_clickstat_fatdt1
(yyyymmdd string,
id INT,
ip string,
country string,
cookie_id string,
page_id string ,
clickstat_url_id int,
query_string string,
refer string
)PARTITIONED BY(dt STRING)
row format delimited fields terminated by ‘\005‘ stored astextfile;
装载数据:
LOAD DATA INPATH‘/user/admin/SqlldrDat/CnClickstat/20101101/19/clickstat_gp_fatdt0/0‘ OVERWRITEINTO TABLE c02_clickstat_fatdt1
PARTITION(dt=‘20101101‘);
访问某一个分区
SELECT count(*)
FROMc02_clickstat_fatdt1 a
WHERE a.dt >=‘20101101‘ AND a.dt < ‘20101102‘;
hive创建分区
标签:hive
原文地址:http://blog.csdn.net/crxy2016/article/details/45038875