hive partition by time

142 Views Asked by At

I want to implement

alter table dos_sourcedata add partition (data = to_date (current_timestamp ()));

in hive

Run this statement at a specific time every day. but this is always wrong.

1

There are 1 best solutions below

0
On

If you want to create empty partition using alter table, use value, not expression, like this:

alter table mytable add partition (partition_date='2020-04-01');

You can create partitions dynamically when loading data using insert overwrite table partition, in this case you can use expression in the query:

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

insert overwrite table mytable partition (partition_date)
select 
      col_1,
      ...
      col_n,
      current_date --partition column is the last one
  from ...

Use current_date instead of to_date (current_timestamp ()).