...
Code Block | ||
---|---|---|
| ||
REPLACE TABLE table_identifier [( [ < physical_column_definition >, ... ] [ < table_constraint >, ... ])] [ COMMENT table_comment ] [ PARTITIONED BY ( col_name1, col_name3, ...) ] [ WITH ( key1=val1, key2=val2, ... ) ] AS <table subquery> <physical_column_definition>: column_name column_type [ <column_constraint> ] [COMMENT column_comment] <column_constraint>: [CONSTRAINT constraint_name] PRIMARY KEY NOT ENFORCED <table_constraint>: [CONSTRAINT constraint_name] PRIMARY KEY (column_name, ...) NOT ENFORCED |
...
Also, we would like to propose to CREATE OR REPLACE TABLE AS
to wrap CREATE TABLE AS SELECT
and REPLACE TABLE AS SELECT
which will create table if the table to be replaced doesn't exist.
Code Block | ||
---|---|---|
| ||
CREATE OR REPLACE TABLE table_identifier [( [ < physical_column_definition >, ... ] [ < table_constraint >, ... ])] [ COMMENT table_comment ] [ PARTITIONED BY ( col_name1, col_name3, ...) ] [ WITH ( key1=val1, key2=val2, ... ) ] AS <table subquery> <physical_column_definition>: column_name column_type [ <column_constraint> ] [COMMENT column_comment] <column_constraint>: [CONSTRAINT constraint_name] PRIMARY KEY NOT ENFORCED <table_constraint>: [CONSTRAINT constraint_name] PRIMARY KEY (column_name, ...) NOT ENFORCED |
Public Interfaces Change
To support atomic, we propose to add the following part to the interface SupportsStaging
proposed in FLIP-305
...
1: Construct the table to be created If the column definition is specificed, it will use the defined column to create the new table. Otherwise, it'll retrieve the column definition from the sub-query.
2: Check the table exists or not. If the table doesn't exist, throw TableException(String.format("The table %s to be replaced doesn't exist. You may want to use CREATE TABLE AS statement or CREATE OR REPLACE TABLE AS statement.",tableIdentifier)).
...