IMPALA-7832: Support for IF NOT EXISTS in ALTER TABLE ADD COLUMN(S)

This patch adds IF NOT EXISTS support in ALTER TABLE ADD COLUMN and
ALTER TABLE ADD COLUMNS. If IF NOT EXISTS is specified and a column
already exists with this name, no error is thrown. If IF NOT EXISTS
is specified for multiple columns and a column already exists, no
error is thrown and a new column that does not exist will be added.

Syntax:
ALTER TABLE tbl ADD COLUMN [IF NOT EXISTS] i int
ALTER TABLE tbl ADD [IF NOT EXISTS] COLUMNS (i int, j int)

Testing:
- Added new FE tests
- Ran all FE tests
- Updated E2E DDL tests
- Ran all E2E DDL tests

Change-Id: I60ed22c8a8eefa10e94ad3dedf32fe67c16642d9
Reviewed-on: http://gerrit.cloudera.org:8080/12181
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
This commit is contained in:
Fredy Wijaya
2019-01-08 12:45:59 -08:00
committed by Impala Public Jenkins
parent 85a8b34645
commit bfb9ccc8e0
11 changed files with 473 additions and 124 deletions

View File

@@ -22,11 +22,65 @@ alter table t1 add columns (t tinyint, s string comment 'Str Col')
string
====
---- QUERY
# Add columns that already exist with "if not exists" clause.
alter table t1 add if not exists columns (t tinyint, s string comment 'Str Col')
---- RESULTS
'No new column(s) have been added to the table.'
---- TYPES
string
====
---- QUERY
# Add columns that do not exist with "if not exists" clause.
alter table t1 add if not exists columns (t2 tinyint, s2 string comment 'Str Col')
---- RESULTS
'New column(s) have been added to the table.'
---- TYPES
string
====
---- QUERY
# Add a column that already exists and a new column that does not exist with
# "if not exists" clause.
alter table t1 add if not exists columns (t3 tinyint, s2 string comment 'Str Col')
---- RESULTS
'New column(s) have been added to the table.'
---- TYPES
string
====
---- QUERY
# Add a new column that does not exist.
alter table t1 add column t4 tinyint
---- RESULTS
'New column(s) have been added to the table.'
---- TYPES
string
====
---- QUERY
# Add a new column that does not exist with "if not exists" clause.
alter table t1 add column if not exists t5 tinyint
---- RESULTS
'New column(s) have been added to the table.'
---- TYPES
string
====
---- QUERY
# Add a new column that already exists with "if not exists" clause.
alter table t1 add column if not exists t5 tinyint
---- RESULTS
'No new column(s) have been added to the table.'
---- TYPES
string
====
---- QUERY
describe t1
---- RESULTS
'i','int',''
't','tinyint',''
's','string','Str Col'
't2','tinyint',''
's2','string','Str Col'
't3','tinyint',''
't4','tinyint',''
't5','tinyint',''
---- TYPES
string,string,string
====
@@ -78,6 +132,11 @@ describe t2
'i','int',''
't','tinyint',''
's','string','Str Col'
't2','tinyint',''
's2','string','Str Col'
't3','tinyint',''
't4','tinyint',''
't5','tinyint',''
---- TYPES
string,string,string
====
@@ -92,6 +151,11 @@ describe t2
---- RESULTS
'i','int',''
's','string','Str Col'
't2','tinyint',''
's2','string','Str Col'
't3','tinyint',''
't4','tinyint',''
't5','tinyint',''
---- TYPES
string,string,string
====

View File

@@ -219,7 +219,7 @@ alter table tbl_to_alter add range partition 1 < values <= 20;
alter table tbl_to_alter add columns (new_col1 int not null default 10,
new_col2 bigint not null default 1000)
---- RESULTS
'Column has been added/replaced.'
'Column(s) have been added.'
====
---- QUERY
# Verify partition layout
@@ -272,7 +272,7 @@ INT,STRING,BIGINT,INT,BIGINT
# Add nullable columns: with and without a default
alter table tbl_to_alter add columns (new_col3 string null, new_col4 int null default -1)
---- RESULTS
'Column has been added/replaced.'
'Column(s) have been added.'
====
---- QUERY
# Add a row

View File

@@ -363,7 +363,7 @@ INT,INT,INT,INT,INT,INT,STRING,BOOLEAN,DECIMAL
---- QUERY
alter table tbl_with_defaults add columns (j int null, k int not null default 10000)
---- RESULTS
'Column has been added/replaced.'
'Column(s) have been added.'
====
---- QUERY
select * from tbl_with_defaults