1

我创建了一个表:

CREATE EXTERNAL TABLE extab (
vendorID string, 
orderID string , 
ordertime string
) 
location '/common_folder/data'

然后我按月和日创建了一个分区

CREATE EXTERNAL TABLE part_extab(
endorID string, 
orderID string , 
ordertime string
) 
PARTITIONED by (month string, day string)
location '/common_folder/data'

然后将数据插入到分区表中

INSERT OVERWRITE TABLE 
select vendorId, orderId, ordertime , month, day
FROM extab

如何从 ordertime 中提取月、日?

4

1 回答 1

0

使用动态分区加载。如果您的日期格式正确,month()并且day()功能将起作用:

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;

INSERT OVERWRITE TABLE part_extab partiion (month, day)
select vendorId, orderId, ordertime , 
       lpad(month(ordertime),2,0) as month,  
       lpad(day(ordertime),2,0) as day
FROM extab;

或者,您可以使用 substr() 提取月份和日期,就像在这个答案中一样

于 2018-09-01T15:18:42.583 回答