AbtPst
AbtPst

Reputation: 8018

Hive : Cannot copy data from unpartitioned table to partitioned table

I have an unpartitioned table

create table tabUn 
(
    col1 string,
    col2 int
)

Lets say it has some data. Next I created a partitioned table

CREATE EXTERNAL TABLE tabPart 
(
    col1 string,
    col2 int
)
PARTITIONED BY (col_date string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE
LOCATION '/path/to/table';

Finally, I tried to copy the data over

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
INSERT OVERWRITE TABLE tabPart PARTITION(data_date='2018-10-01')
SELECT 
(
    col1,
    col2,
    '2018-10-01' as col_date
) select * FROM tabUn;

but I get the below error

FAILED: NullPointerException null

What am I doing wrong?

Upvotes: 0

Views: 104

Answers (1)

nobody
nobody

Reputation: 11090

Your select statement seems to be incorrect.

INSERT OVERWRITE TABLE tabPart PARTITION (data_date='2018-10-01')
SELECT col1,col2,'2018-10-01' as col_date from tabUn;

Upvotes: 1

Related Questions