我是分区的新手。
假设我有下表
table mytable(mytime timestamp,myname string)
列mytime如下:year-month-day hour:min:sec.msec(例如,2014-12-05 08:55:59.3131)
我想基于mytime的年月日来分区mytable
例如,我想为2014-12-05制作分区
具有mytime的记录如2014-12-05 08:55:59,3131将在此分区中。
因此像select * from mytable where mytime='2014-12-05%'
这样的查询会搜索
分区。
我怎样才能在蜂巢中做到这一点?
我已经在mytable中有数据,我是否需要重新创建mytable并重新加载所有数据?
谢谢
答案 0 :(得分:0)
输入
1997-12-31 23:59:59.999,kishore
2014-12-31 23:59:59.999999,manish
create table mytable_tmp(mytime string,myname string)
row format delimited
fields terminated by ',';
load data local inpath 'input.txt'
overwrite into table mytable_tmp;
create table mytable(myname string,mytimestamp string)
PARTITIONED BY (mydate string)
row format delimited
fields terminated by ',';
SET hive.exec.dynamic.partition = true;
SET hive.exec.dynamic.partition.mode = nonstrict;
INSERT OVERWRITE TABLE mytable PARTITION(mydate)
SELECT myname,mytime,to_date(mytime) from mytable_tmp;
select * from mytable where mydate='2014-12-31';
manish 2014-12-31 23:59:59.999999 2014-12-31
根据你的问题,有分区mydate,包括myname和mytime;