0

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.

leftjoin
  • 36,950
  • 8
  • 57
  • 116
  • Can you clarify exactly what you mean by "this is always wrong"? – David Buck Mar 29 '20 at 14:16
  • `partition_specification` must be a value, it can not be an SQL expression. https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AddPartitions. – mazaneicha Mar 29 '20 at 14:46

1 Answers1

0

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 ()).

leftjoin
  • 36,950
  • 8
  • 57
  • 116