mirror of
https://github.com/apache/impala.git
synced 2026-02-02 15:00:38 -05:00
Kudu engine recently enables the auto-incrementing column feature (KUDU-1945). The feature works by appending a system generated auto-incrementing column to the primary key columns to guarantee the uniqueness on primary key when the primary key columns can be non unique. The non unique primary key columns and the auto-incrementing column form the effective unique composite primary key. This auto-incrementing column is named as 'auto_incrementing_id' with big int type. The assignment to it during insertion is automatic so insertion statements should not specify values for auto-incrementing column. In current Kudu implementation, there is no central key provider for auto-incrementing columns. It uses a per tablet-server global counter to assign values for auto-incrementing columns. So the values of auto-incrementing columns are not unique in a Kudu table, but unique within a continuous region of the table served by a tablet-server. This patch also upgraded Kudu version to 345fd44ca3 to pick up Kudu changes needed for supporting non-unique primary key. It added syntactic support for creating Kudu table with non unique primary key. When creating a Kudu table, specifying PRIMARY KEY is optional. If there is no primary key attribute specified, the partition key columns will be promoted as non unique primary key if those columns are the beginning columns of the table. New column "key_unique" is added to the output of 'describe' table command for Kudu table. Examples of CREATE TABLE statement with non unique primary key: CREATE TABLE tbl (i INT NON UNIQUE PRIMARY KEY, s STRING) PARTITION BY HASH (i) PARTITIONS 3 STORED as KUDU; CREATE TABLE tbl (i INT, s STRING, NON UNIQUE PRIMARY KEY(i)) PARTITION BY HASH (i) PARTITIONS 3 STORED as KUDU; CREATE TABLE tbl NON UNIQUE PRIMARY KEY(id) PARTITION BY HASH (id) PARTITIONS 3 STORED as KUDU AS SELECT id, string_col FROM functional.alltypes WHERE id = 10; CREATE TABLE tbl NON UNIQUE PRIMARY KEY(id) PARTITION BY RANGE (id) (PARTITION VALUES <= 1000, PARTITION 1000 < VALUES <= 2000, PARTITION 2000 < VALUES <= 3000, PARTITION 3000 < VALUES) STORED as KUDU AS SELECT id, int_col FROM functional.alltypestiny ORDER BY id ASC LIMIT 4000; CREATE TABLE tbl (id INT, name STRING, NON UNIQUE PRIMARY KEY(id)) STORED as KUDU; CREATE TABLE tbl (a INT, b STRING, c FLOAT) PARTITION BY HASH (a, b) PARTITIONS 3 STORED as KUDU; SELECT statement does not show the system generated auto-incrementing column unless the column is explicitly specified in the select list. Auto-incrementing column cannot be added, removed or renamed with ALTER TABLE statements. UPSERT operation is not supported now for Kudu tables with auto incrementing column due to limitation in Kudu engine. Testing: - Ran manual test in impala-shell with queries to create Kudu tables with non unique primary key, and tested insert/update/delete operations for these tables with non unique primary key. - Added front end tests, and end to end unit tests for Kudu tables with non unique primary key. - Passed exhaustive test. Change-Id: I4d7882bf3d01a3492cc9827c072d1f3200d9eebd Reviewed-on: http://gerrit.cloudera.org:8080/19383 Reviewed-by: Riza Suminto <riza.suminto@cloudera.com> Reviewed-by: Wenzhe Zhou <wzhou@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
646 lines
19 KiB
Plaintext
646 lines
19 KiB
Plaintext
====
|
|
---- QUERY
|
|
create table t primary key (id) partition by hash (id) partitions 3
|
|
stored as kudu
|
|
as select id, int_col from functional.alltypestiny;
|
|
select * from t;
|
|
---- RESULTS
|
|
0,0
|
|
1,1
|
|
2,0
|
|
3,1
|
|
4,0
|
|
5,1
|
|
6,0
|
|
7,1
|
|
---- TYPES
|
|
INT,INT
|
|
====
|
|
---- QUERY
|
|
# Boolean primary key column
|
|
create table tab (x int, y boolean, primary key(x, y))
|
|
partition by hash (x) partitions 3 stored as kudu
|
|
---- CATCH
|
|
NonRecoverableException: key column may not have type of BOOL, FLOAT, or DOUBLE
|
|
====
|
|
---- QUERY
|
|
# Float primary key column
|
|
create table tab (x int, y float, primary key(x, y))
|
|
partition by hash (x) partitions 3 stored as kudu
|
|
---- CATCH
|
|
NonRecoverableException: key column may not have type of BOOL, FLOAT, or DOUBLE
|
|
====
|
|
---- QUERY
|
|
# Primary keys should be declared first
|
|
create table tab (x int, y int, primary key(y))
|
|
partition by hash (y) partitions 3 stored as kudu
|
|
---- CATCH
|
|
ImpalaRuntimeException: Kudu PRIMARY KEY columns must be specified as the first columns in the table (expected leading columns ('y') but found ('x'))
|
|
====
|
|
---- QUERY
|
|
# Primary keys should be be listed in the same order
|
|
create table tab (x int, y int, z int, primary key(y,x))
|
|
partition by hash (y) partitions 3 stored as kudu
|
|
---- CATCH
|
|
ImpalaRuntimeException: Kudu PRIMARY KEY columns must be specified as the first columns in the table (expected leading columns ('y', 'x') but found ('x', 'y'))
|
|
====
|
|
---- QUERY
|
|
# Small number of hash partitions
|
|
create table tab (a int, b int, c int, d int, primary key(a, b, c))
|
|
partition by hash(a,b) partitions 8, hash(c) partitions 1 stored as kudu
|
|
---- CATCH
|
|
NonRecoverableException: must have at least two hash buckets
|
|
====
|
|
---- QUERY
|
|
# Same column in multiple hash based distributions
|
|
create table tab (a int, b int, primary key (a))
|
|
partition by hash (a) partitions 3, hash (a) partitions 2 stored as kudu
|
|
---- CATCH
|
|
NonRecoverableException: hash bucket schema components must not contain columns in common
|
|
====
|
|
---- QUERY
|
|
# Same column referenced multiple times in the same hash-based distribution
|
|
create table tab (a int primary key) partition by hash (a, a, a) partitions 3
|
|
stored as kudu
|
|
---- CATCH
|
|
NonRecoverableException: hash bucket schema components must not contain columns in common
|
|
====
|
|
---- QUERY
|
|
# Kudu table that uses Impala keywords as table name and column names
|
|
create table `add`(`analytic` int, `function` int, primary key(`analytic`, `function`))
|
|
partition by hash (`analytic`) partitions 4, range (`function`)
|
|
(partition values <= 1, partition 1 < values <= 10, partition 10 < values) stored as kudu;
|
|
insert into `add` select id, int_col from functional.alltypestiny;
|
|
select * from `add`
|
|
---- RESULTS
|
|
0,0
|
|
1,1
|
|
2,0
|
|
3,1
|
|
4,0
|
|
5,1
|
|
6,0
|
|
7,1
|
|
---- TYPES
|
|
INT,INT
|
|
====
|
|
---- QUERY
|
|
# Test implicit casting/folding of partition values.
|
|
create table tab (a int not null primary key)
|
|
partition by range (a) (partition value = false)
|
|
stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
# Invalid hostname
|
|
create table tdata_bogus_host (id int primary key, name string, valf float, vali bigint)
|
|
PARTITION BY RANGE (PARTITION 10 <= VALUES <= 30) STORED AS KUDU
|
|
TBLPROPERTIES('kudu.master_addresses' = 'bogus host name')
|
|
---- CATCH
|
|
Couldn't resolve this master's address bogus host name:7051
|
|
====
|
|
---- QUERY
|
|
# Non-existing host
|
|
create table tdata_non_existing_host
|
|
(id int primary key, name string, valf float, vali bigint)
|
|
PARTITION BY RANGE (PARTITION 10 <= VALUES <= 30) STORED AS KUDU
|
|
TBLPROPERTIES('kudu.master_addresses' = 'bogus.host.name')
|
|
---- CATCH
|
|
Couldn't resolve this master's address bogus.host.name:7051
|
|
====
|
|
---- QUERY
|
|
# Valid host with whitespace
|
|
create table tdata_master_addresses_whitespace (id int primary key) stored as kudu
|
|
tblproperties('kudu.master_addresses' = ' $INTERNAL_LISTEN_HOST ')
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
insert into tdata_master_addresses_whitespace values (0), (1)
|
|
---- DML_RESULTS: tdata_master_addresses_whitespace
|
|
0
|
|
1
|
|
====
|
|
---- QUERY
|
|
# Test that string case is ignored
|
|
create table ignore_column_case (Id int, NAME string, vAlf float, vali bigint,
|
|
primary key (Id, NAME)) PARTITION BY RANGE (PARTITION VALUE = (1, 'Martin'))
|
|
STORED AS KUDU
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
insert into ignore_column_case values (1, 'Martin', 1.0, 10);
|
|
---- RESULTS
|
|
: 1
|
|
---- RUNTIME_PROFILE
|
|
NumModifiedRows: 1
|
|
NumRowErrors: 0
|
|
====
|
|
---- QUERY
|
|
select ID, nAmE, VALF, VALI from ignore_column_case where NaMe = 'Martin';
|
|
---- RESULTS
|
|
1,'Martin',1.0,10
|
|
---- TYPES
|
|
INT,STRING,FLOAT,BIGINT
|
|
====
|
|
---- QUERY
|
|
# Using NULL as default values
|
|
create table tbl_with_null_defaults (x int primary key, i1 tinyint default null,
|
|
i2 smallint default null, i3 int default null, i4 bigint default null,
|
|
vals string default null, valf float default null, vald double default null,
|
|
valb boolean default null, valdec4 decimal(9) default null,
|
|
valdec8 decimal(18) default null, valdec16 decimal(38) default null,
|
|
valdate date default null, valvc varchar(2000) default null)
|
|
partition by hash (x) partitions 3 stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
insert into tbl_with_null_defaults (x) values (1);
|
|
---- RUNTIME_PROFILE
|
|
NumModifiedRows: 1
|
|
NumRowErrors: 0
|
|
---- LABELS
|
|
X, I1, I2, I3, I4, VALS, VALF, VALD, VALB, VALDEC4, VALDEC8, VALDEC16, VALDATE, VALVC
|
|
---- DML_RESULTS: tbl_with_null_defaults
|
|
1,NULL,NULL,NULL,NULL,'NULL',NULL,NULL,NULL,NULL,NULL,NULL,NULL,'NULL'
|
|
---- TYPES
|
|
INT,TINYINT,SMALLINT,INT,BIGINT,STRING,FLOAT,DOUBLE,BOOLEAN,DECIMAL,DECIMAL,DECIMAL,DATE,STRING
|
|
====
|
|
---- QUERY
|
|
# Overlapping ranges are rejected by the Kudu client
|
|
create table ts_ranges (ts timestamp primary key, i int)
|
|
partition by range (
|
|
partition cast('2009-01-02 00:00:00' as timestamp) <= VALUES <
|
|
cast('2009-01-03 00:00:00' as timestamp),
|
|
partition cast('2009-01-02 10:00:00' as timestamp) <= VALUES
|
|
) stored as kudu
|
|
---- CATCH
|
|
NonRecoverableException: overlapping range partitions: first range partition: 2009-01-02T00:00:00.000000Z <= VALUES < 2009-01-03T00:00:00.000000Z, second range partition: 2009-01-02T10:00:00.000000Z <= VALUES
|
|
====
|
|
---- QUERY
|
|
# Creates a range partitioned Kudu table with a timestamp PK. Note that nanoseconds
|
|
# are rounded (same behavior as when writing timestamp values to Kudu).
|
|
create table ts_ranges (ts timestamp primary key, i int)
|
|
partition by range (
|
|
partition nanoseconds_add(cast('2009-01-01 00:00:00' as timestamp), 999) <= VALUES <
|
|
nanoseconds_add(cast('2009-01-02 00:00:00' as timestamp), 1),
|
|
partition cast('2009-01-02 00:00:00' as timestamp) <= VALUES <
|
|
cast('2009-01-03 00:00:00' as timestamp),
|
|
partition '2009-01-03 00:00:00' <= VALUES
|
|
) stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
show range partitions ts_ranges
|
|
---- RESULTS
|
|
'2009-01-01T00:00:00.000001Z <= VALUES < 2009-01-02T00:00:00.000000Z'
|
|
'2009-01-02T00:00:00.000000Z <= VALUES < 2009-01-03T00:00:00.000000Z'
|
|
'VALUES >= 2009-01-03T00:00:00.000000Z'
|
|
---- TYPES
|
|
STRING
|
|
====
|
|
---- QUERY
|
|
create table ts_ranges_ctas
|
|
primary key (ts)
|
|
partition by range (
|
|
partition VALUES < '2009-01-02 00:00:00',
|
|
partition '2009-01-02 00:00:00' <= VALUES <
|
|
'2009-01-03 00:00:00',
|
|
partition '2009-01-03 00:00:00' < VALUES,
|
|
partition VALUE = ('2009-01-03 00:00:00')
|
|
)
|
|
stored as kudu
|
|
as select timestamp_col ts, id from functional.alltypestiny;
|
|
---- RESULTS
|
|
'Inserted 8 row(s)'
|
|
====
|
|
---- QUERY
|
|
show range partitions ts_ranges_ctas
|
|
---- RESULTS
|
|
'VALUES < 2009-01-02T00:00:00.000000Z'
|
|
'2009-01-02T00:00:00.000000Z <= VALUES < 2009-01-03T00:00:00.000000Z'
|
|
'VALUE = 2009-01-03T00:00:00.000000Z'
|
|
'VALUES >= 2009-01-03T00:00:00.000001Z'
|
|
---- TYPES
|
|
STRING
|
|
====
|
|
---- QUERY
|
|
select * from ts_ranges_ctas order by id
|
|
---- RESULTS
|
|
2009-01-01 00:00:00,0
|
|
2009-01-01 00:01:00,1
|
|
2009-02-01 00:00:00,2
|
|
2009-02-01 00:01:00,3
|
|
2009-03-01 00:00:00,4
|
|
2009-03-01 00:01:00,5
|
|
2009-04-01 00:00:00,6
|
|
2009-04-01 00:01:00,7
|
|
---- TYPES
|
|
TIMESTAMP,INT
|
|
====
|
|
---- QUERY
|
|
# Creates a Kudu table with timestamp column default values.
|
|
create table ts_default (i int primary key, ts1 timestamp,
|
|
ts2 timestamp default cast('2009-01-01 00:00:00' as timestamp))
|
|
partition by hash(i) partitions 3 stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
insert into ts_default (i) values (1);
|
|
---- RUNTIME_PROFILE
|
|
NumModifiedRows: 1
|
|
NumRowErrors: 0
|
|
---- LABELS
|
|
I, TS1, TS2
|
|
---- DML_RESULTS: ts_default
|
|
1,NULL,2009-01-01 00:00:00
|
|
---- TYPES
|
|
INT,TIMESTAMP,TIMESTAMP
|
|
====
|
|
---- QUERY
|
|
insert into ts_default (i, ts1, ts2) values (2, NULL, NULL);
|
|
---- RUNTIME_PROFILE
|
|
NumModifiedRows: 1
|
|
NumRowErrors: 0
|
|
---- LABELS
|
|
I, TS1, TS2
|
|
---- DML_RESULTS: ts_default
|
|
1,NULL,2009-01-01 00:00:00
|
|
2,NULL,NULL
|
|
---- TYPES
|
|
INT,TIMESTAMP,TIMESTAMP
|
|
====
|
|
---- QUERY
|
|
# create an unpartitioned table
|
|
create table unpartitioned_kudu_table (col0 bigint primary key, col1 string)
|
|
stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
---- ERRORS
|
|
Unpartitioned Kudu tables are inefficient for large data sizes.
|
|
====
|
|
---- QUERY
|
|
insert into unpartitioned_kudu_table values (0, 'zero'), (1, 'one')
|
|
---- RUNTIME_PROFILE
|
|
NumModifiedRows: 2
|
|
NumRowErrors: 0
|
|
---- LABELS
|
|
COL0,COL1
|
|
---- DML_RESULTS: unpartitioned_kudu_table
|
|
0,'zero'
|
|
1,'one'
|
|
---- TYPES
|
|
BIGINT,STRING
|
|
====
|
|
---- QUERY
|
|
create table unpartitioned_kudu_table2 primary key(id) stored as kudu
|
|
as select id from functional.alltypestiny where id > 4
|
|
---- RESULTS
|
|
'Inserted 3 row(s)'
|
|
---- ERRORS
|
|
Unpartitioned Kudu tables are inefficient for large data sizes.
|
|
====
|
|
---- QUERY
|
|
select * from unpartitioned_kudu_table2
|
|
---- RESULTS
|
|
5
|
|
6
|
|
7
|
|
---- LABELS
|
|
ID
|
|
---- TYPES
|
|
INT
|
|
====
|
|
---- QUERY
|
|
# Creates a Kudu table with decimal columns and primary key
|
|
create table create_decimal
|
|
(
|
|
decimal_4 decimal(9, 9),
|
|
decimal_8 decimal(18, 2) not null default 100.00,
|
|
decimal_16 decimal(38, 0) null,
|
|
primary key (decimal_4))
|
|
stored as kudu;
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
# Create as select table with decimal columns and primary key
|
|
create table ctas_decimal primary key (d1,d2,d3)
|
|
stored as kudu
|
|
as select * from functional.decimal_tbl;
|
|
select * from ctas_decimal;
|
|
---- RESULTS
|
|
1234,2222,1.2345678900,0.12345678900000000000000000000000000000,12345.78900,1
|
|
2345,111,12.3456789000,0.12345678900000000000000000000000000000,3.14100,1
|
|
12345,333,123.4567890000,0.12345678900000000000000000000000000000,11.22000,1
|
|
12345,333,1234.5678900000,0.12345678900000000000000000000000000000,0.10000,1
|
|
132842,333,12345.6789000000,0.12345678900000000000000000000000000000,0.77889,1
|
|
---- TYPES
|
|
DECIMAL,DECIMAL,DECIMAL,DECIMAL,DECIMAL,DECIMAL
|
|
====
|
|
---- QUERY
|
|
# IMPALA-6954: CTAS with an expr rewrite.
|
|
create table ctas_rewrite primary key(id)
|
|
partition by range(id) (partition 0 <= values < 100) stored as kudu
|
|
as select id, tinyint_col from functional.alltypes
|
|
where id between 0 and 1;
|
|
show range partitions ctas_rewrite;
|
|
---- RESULTS
|
|
'0 <= VALUES < 100'
|
|
====
|
|
---- QUERY
|
|
# create table with primary key of DATE type
|
|
create table kudu_date_key (fdatekey date primary key, val string)
|
|
stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
---- ERRORS
|
|
Unpartitioned Kudu tables are inefficient for large data sizes.
|
|
====
|
|
---- QUERY
|
|
insert into kudu_date_key values (DATE '1970-01-01', 'Unix epoch'), (DATE '2019-12-12', 'today')
|
|
---- RUNTIME_PROFILE
|
|
NumModifiedRows: 2
|
|
NumRowErrors: 0
|
|
---- LABELS
|
|
FDATEKEY,VAL
|
|
---- DML_RESULTS: kudu_date_key
|
|
1970-01-01,'Unix epoch'
|
|
2019-12-12,'today'
|
|
---- TYPES
|
|
DATE,STRING
|
|
====
|
|
---- QUERY
|
|
# create table with invalid default DATE value
|
|
create table kudu_invalid_default_date (fdate date default DATE '111111-33-33')
|
|
stored as kudu
|
|
---- CATCH
|
|
AnalysisException: Invalid date literal: '111111-33-33'
|
|
====
|
|
---- QUERY
|
|
# create table with DATE primary key partitioned by range
|
|
create table kudu_datepk_range (fdate DATE not null primary key)
|
|
partition by range (fdate)
|
|
(
|
|
partition values < DATE '1900-01-01',
|
|
partition DATE '1900-01-01' <= values < DATE '1970-01-01',
|
|
partition DATE '1970-01-01' <= values < DATE '2000-01-01',
|
|
partition DATE '2000-01-01' <= values
|
|
)
|
|
stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
insert into kudu_datepk_range values
|
|
(DATE '1800-01-01'),
|
|
(DATE '1970-01-01'),
|
|
(DATE '2019-12-12')
|
|
---- RUNTIME_PROFILE
|
|
NumModifiedRows: 3
|
|
NumRowErrors: 0
|
|
---- LABELS
|
|
FDATE
|
|
---- DML_RESULTS: kudu_datepk_range
|
|
1800-01-01
|
|
1970-01-01
|
|
2019-12-12
|
|
---- TYPES
|
|
DATE
|
|
====
|
|
---- QUERY
|
|
select * from kudu_datepk_range;
|
|
---- RESULTS
|
|
1800-01-01
|
|
1970-01-01
|
|
2019-12-12
|
|
---- TYPES
|
|
DATE
|
|
====
|
|
---- QUERY
|
|
# Creates a Kudu table with varchar columns, primary key,
|
|
# hash partition and range partition.
|
|
create table create_varchar
|
|
(
|
|
valvc varchar(10),
|
|
primary key (valvc))
|
|
partition by hash (valvc) partitions 4, range (valvc) (
|
|
partition values < cast('m' as VARCHAR(10)),
|
|
partition cast('m' as VARCHAR(10)) <= values)
|
|
stored as kudu;
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
insert into create_varchar values
|
|
(cast('a' as VARCHAR(10))),
|
|
(cast('m' as VARCHAR(10))),
|
|
(cast('z' as VARCHAR(10)))
|
|
---- RUNTIME_PROFILE
|
|
NumModifiedRows: 3
|
|
NumRowErrors: 0
|
|
---- LABELS
|
|
VALVC
|
|
---- DML_RESULTS: create_varchar
|
|
'a'
|
|
'm'
|
|
'z'
|
|
---- TYPES
|
|
STRING
|
|
====
|
|
---- QUERY
|
|
# Creates as select table with varchar columns and primary key
|
|
create table ctas_varchar primary key (vc)
|
|
stored as kudu
|
|
as select vc from functional.chars_tiny;
|
|
select * from ctas_varchar;
|
|
---- RESULTS
|
|
'1cccc'
|
|
'2cccccc'
|
|
'3ccc'
|
|
'4cc'
|
|
'5c'
|
|
'6c'
|
|
'c'
|
|
---- TYPES
|
|
STRING
|
|
====
|
|
---- QUERY
|
|
# Create with keyword 'stored by'
|
|
create table kudu_stored_by (i int primary key, s string, ts timestamp, d date) stored by kudu;
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
describe formatted kudu_stored_by;
|
|
---- RESULTS: VERIFY_IS_SUBSET
|
|
'','storage_handler ','org.apache.hadoop.hive.kudu.KuduStorageHandler'
|
|
---- TYPES
|
|
string, string, string
|
|
====
|
|
---- QUERY
|
|
# Create Kudu table with non unique primary key
|
|
create table non_unique_key_create_tbl1 (id int non unique primary key, name string)
|
|
partition by hash (id) partitions 3
|
|
stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
insert into non_unique_key_create_tbl1 values (1,'Martin'), (2,'Smith');
|
|
---- RESULTS
|
|
: 2
|
|
---- RUNTIME_PROFILE
|
|
NumModifiedRows: 2
|
|
NumRowErrors: 0
|
|
====
|
|
---- QUERY
|
|
# auto-incrementing column is not shown for "select *"
|
|
select * from non_unique_key_create_tbl1 where name = 'Martin';
|
|
---- RESULTS
|
|
1,'Martin'
|
|
---- TYPES
|
|
INT,STRING
|
|
====
|
|
---- QUERY
|
|
# Create Kudu table with non unique composite primary key
|
|
create table non_unique_key_create_tbl2 (a int, b string, non unique primary key(a, b))
|
|
partition by hash (a) partitions 3
|
|
stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
# Create Kudu table with non unique composite primary key
|
|
create table non_unique_key_create_tbl3 (a string, b int, non unique primary key(a, b))
|
|
partition by hash (a) partitions 3
|
|
stored as kudu
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
# Create Kudu table without primary key columns,
|
|
# partition columns will be promoted as non unique primary key columns.
|
|
create table promote_partition_keys_as_non_unique_keys_test (a int, b string, c float)
|
|
partition by hash (a, b) partitions 3
|
|
stored as kudu;
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
---- ERRORS
|
|
Partition columns (a, b) are promoted as non unique primary key.
|
|
====
|
|
---- QUERY
|
|
# Create Kudu table without primary key columns,
|
|
# partition columns cannot be promoted as non unique primary key columns since the columns
|
|
# are not beginning columns of the table.
|
|
create table partition_keys_not_promoted_test (a int, b string, c float)
|
|
partition by hash (b, c) partitions 3
|
|
stored as kudu;
|
|
---- CATCH
|
|
AnalysisException: Specify primary key or non unique primary key for the Kudu table, or create partitions with the beginning columns of the table.
|
|
====
|
|
---- QUERY
|
|
# Create unpartitioned Kudu table with non unique primary key column.
|
|
create table non_unique_key_create_tbl4 (a int non unique primary key, b string)
|
|
stored as kudu;
|
|
---- RESULTS
|
|
'Table has been created.'
|
|
====
|
|
---- QUERY
|
|
# Create Kudu table in CTAS statement with non unique primary key
|
|
create table non_unique_key_create_tbl5 non unique primary key (id)
|
|
partition by hash (id) partitions 3
|
|
stored as kudu
|
|
as select id, int_col from functional.alltypestiny;
|
|
select * from non_unique_key_create_tbl5 order by id asc;
|
|
---- RESULTS
|
|
0,0
|
|
1,1
|
|
2,0
|
|
3,1
|
|
4,0
|
|
5,1
|
|
6,0
|
|
7,1
|
|
---- TYPES
|
|
INT,INT
|
|
====
|
|
---- QUERY
|
|
# Create Kudu table in CTAS statement with non unique primary key and range partitions
|
|
create table non_unique_key_create_tbl6 non unique primary key (id)
|
|
partition by range (id) (partition values <= 1, partition 1 < values <= 3,
|
|
partition 3 < values <= 5, partition 5 < values)
|
|
stored as kudu
|
|
as select id, int_col from functional.alltypestiny order by id asc limit 100;
|
|
select id, int_col, auto_incrementing_id from non_unique_key_create_tbl6 order by id asc;
|
|
---- RESULTS
|
|
0,0,1
|
|
1,1,2
|
|
2,0,1
|
|
3,1,2
|
|
4,0,1
|
|
5,1,2
|
|
6,0,1
|
|
7,1,2
|
|
---- TYPES
|
|
INT,INT,BIGINT
|
|
====
|
|
---- QUERY
|
|
# Non unique primary key for non Kudu table
|
|
create table non_unique_key_create_tbl7 (x int, y boolean, non unique primary key(x, y))
|
|
---- CATCH
|
|
AnalysisException: NON UNIQUE PRIMARY KEY is only supported for Kudu
|
|
====
|
|
---- QUERY
|
|
# Non unique primary keys should be declared first
|
|
create table non_unique_key_create_tbl8 (x int, y int, non unique primary key(y))
|
|
partition by hash (y) partitions 3 stored as kudu
|
|
---- CATCH
|
|
ImpalaRuntimeException: Kudu NON UNIQUE PRIMARY KEY columns must be specified as the first columns in the table (expected leading columns ('y') but found ('x'))
|
|
====
|
|
---- QUERY
|
|
# Non unique primary keys should be be listed in the same order
|
|
create table non_unique_key_create_tbl9 (x int, y int, z int, non unique primary key(y,x))
|
|
partition by hash (y) partitions 3 stored as kudu
|
|
---- CATCH
|
|
ImpalaRuntimeException: Kudu NON UNIQUE PRIMARY KEY columns must be specified as the first columns in the table (expected leading columns ('y', 'x') but found ('x', 'y'))
|
|
====
|
|
---- QUERY
|
|
# Non unique primary key cannot be boolean type
|
|
create table non_unique_key_create_tbl10 (x boolean non unique primary key)
|
|
partition by hash(x) partitions 8 stored as kudu
|
|
---- CATCH
|
|
NonRecoverableException: key column may not have type of BOOL, FLOAT, or DOUBLE
|
|
====
|
|
---- QUERY
|
|
# Non unique primary key cannot be float type
|
|
create table non_unique_key_create_tbl11 (x float non unique primary key)
|
|
partition by hash(x) partitions 8 stored as kudu
|
|
---- CATCH
|
|
NonRecoverableException: key column may not have type of BOOL, FLOAT, or DOUBLE
|
|
====
|
|
---- QUERY
|
|
# Non unique primary key cannot be double type
|
|
create table non_unique_key_create_tbl12 (x double non unique primary key)
|
|
partition by hash(x) partitions 8 stored as kudu
|
|
---- CATCH
|
|
NonRecoverableException: key column may not have type of BOOL, FLOAT, or DOUBLE
|
|
====
|
|
---- QUERY
|
|
# Cannot create a Kudu table without any key and partition
|
|
create table non_unique_key_create_tbl13 (x int) stored as kudu
|
|
---- CATCH
|
|
AnalysisException: A primary key is required for a Kudu table.
|
|
====
|
|
---- QUERY
|
|
# Cannot create a Kudu table with a column named as "auto_incrementing_id"
|
|
create table non_unique_key_create_tbl14 (id int primary key, auto_incrementing_id bigint)
|
|
partition by hash(id) partitions 3 stored as kudu
|
|
---- CATCH
|
|
IllegalArgumentException: Column name auto_incrementing_id is reserved by Kudu engine
|
|
==== |