【问题标题】:How to partition a table by month and day in hive如何在 hive 中按月和日对表进行分区
【发布时间】:2018-09-01 14:57:38
【问题描述】:

我创建了一个表:

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 中提取月、日??

【问题讨论】:

    标签: hive hiveql hive-partitions


    【解决方案1】:

    使用动态分区加载。如果您的日期格式正确,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() 提取月份和日期,例如 this 答案

    【讨论】:

      猜你喜欢
      • 2015-11-02
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      • 2020-12-24
      • 2016-02-21
      • 1970-01-01
      相关资源
      最近更新 更多