When inserting data into an already partitioned table, you may encounter this error:
1
| Need to specify partition columns because the destination table is partition
|
The reason is that you need to specify the partition field values in the insert statement.
For example:
Create Table Statements:
1
2
3
4
5
6
7
8
9
| CREATE TABLE test (
starttime STRING,
endtime STRING,
title STRING
)
PARTITIONED BY (username STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
STORED AS TEXTFILE;
|
1
2
3
4
5
6
7
8
9
| CREATE TABLE test2 (
starttime STRING,
endtime STRING,
title STRING
)
PARTITIONED BY (username STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
STORED AS TEXTFILE;
|
Insert Statement:
1
2
| INSERT INTO TABLE test PARTITION(username='admin')
SELECT starttime, endtime, title FROM test2 WHERE username = 'admin';
|