Reply
Explorer
Posts: 6
Registered: ‎11-16-2016

IMPALA: Adding PRIMARY KEY while doing CREATE TABLE AS SELECT

I am creating an Impala table stored as Kudu using the command as mentioned below.

 

create table if not exists bit_nnet.bit_feature_matrix_100
comment 'Table to store the feature matrix'
stored as kudu
as
select * from bit_nnet.bit_feature_matrix_100_ext;

 

The source table "feature_matrix_100_ext" is a regular Impala external table which does not have a primary key. Hence, when I'm trying to create the table, getting an error that a primary key is required for a Kudu table (which is quite natural)!

 

The following is the error I'm getting:

AnalysisException: A primary key is required for a Kudu table.

Any idea how to overcome this issue?

 

Note: I am using the Hue interface for doing the aforesaid

Highlighted
Cloudera Employee
Posts: 47
Registered: ‎02-05-2016

Re: IMPALA: Adding PRIMARY KEY while doing CREATE TABLE AS SELECT

There's no workaround for this yet. For the time being, every Kudu table must have a primary key, and it must be populated if loading data from a table without primary keys.
Contributor
Posts: 25
Registered: ‎06-13-2017

Re: IMPALA: Adding PRIMARY KEY while doing CREATE TABLE AS SELECT

there is a uuid function in impala that you can use to generate surrogate keys for kudu. or you can write an impala udf to generate unique bigints.