Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Any work round to avoid duplicate records in impala for Primary key column

avatar
Explorer

Appreciate if any work round to avoid duplicate records in impala for Primary key column.

1 ACCEPTED SOLUTION

avatar
Champion

Impala does not have a concept of PK .However You have two options 

down the road if you want to implement delete single row you cant perform them on Hive / Impala . So you can implement using Impala-kudu format . Kudu format you can create table with primary key , plus you perform single row delete. 

 

or the hard way to achive this is to 

 

 

STEP 1

CREATE TABLE Sample ( name STRING, street STRING, RD123 Timestamp ,(Assume this is unique since we dont have Pk) ) STEP 2
Perform the LOAD DATA INTO Sample
STEP 3 - Create another table
Create table sample_no_dupli AS select SELECT col1,col2,MAX(RD123) AS createdate FROM JLT_STAHING GROUP BY name,street

 

 

 

View solution in original post

7 REPLIES 7

avatar
Champion

Are you asking pertain to inseration or reterival of data ?

avatar
Explorer

thinking of avoidng duplicates while insertion if this won't cause performacne issue.

avatar
Champion

@Msdhan

 

https://www.cloudera.com/documentation/enterprise/5-3-x/topics/impala_porting.html

 

According to the above link, Take out any CREATE INDEXDROP INDEX, and ALTER INDEX statements, and equivalent ALTER TABLEstatements. Remove any INDEXKEY, or PRIMARY KEY clauses from CREATE TABLE and ALTER TABLE statements. Impala is optimized for bulk read operations for data warehouse-style queries, and therefore does not support indexes for its tables.

 

Yes in general, you cannot achieve both Performance and Indexing. So if possible, you can try to control duplicate in the source (select) portion instead of target (insert) portion

 

Ex:

insert into table trg_table 

select * from src_table

 

 

 

avatar
Explorer
Thanks Saranvisa for this explanation

avatar
Champion

Impala does not have a concept of PK .However You have two options 

down the road if you want to implement delete single row you cant perform them on Hive / Impala . So you can implement using Impala-kudu format . Kudu format you can create table with primary key , plus you perform single row delete. 

 

or the hard way to achive this is to 

 

 

STEP 1

CREATE TABLE Sample ( name STRING, street STRING, RD123 Timestamp ,(Assume this is unique since we dont have Pk) ) STEP 2
Perform the LOAD DATA INTO Sample
STEP 3 - Create another table
Create table sample_no_dupli AS select SELECT col1,col2,MAX(RD123) AS createdate FROM JLT_STAHING GROUP BY name,street

 

 

 

avatar
Explorer

csguna, appreciate your inputs. will try this.

avatar
Champion

@Msdhan You Welcome :))