Search code examples
sqlhadoophivehive-partitions

Getting Exception while using Timeline column as Hive Partition Field


I am trying to load data from normal table to Hive partitioned table.

Here is my normal table syntax:

create table x(name string, date1 string);

Here is my new partitioned table syntax:

create table y (name string, date1 string) partitioned by (timestamp1 string);

Here is how I am how to load data to y:

insert into table y PARTITION(SUBSTR(date1,0,2)) select name, date1 from x;

Here is my Exception:

FAILED: ParseException line 1:39 missing ) at '(' near ',' in column name
line 1:51 cannot recognize input near '0' ',' '2' in column name

Solution

  • Use dynamic partitioning:

    set hive.exec.dynamic.partition=true; 
    set hive.exec.dynamic.partition.mode=nonstrict;
    
    insert into table y PARTITION(timestamp1) 
    select name, date1, SUBSTR(date1,0,2) as timestamp1  from x;