tencent cloud

Feedback

DDL Statement

Last updated: 2024-08-07 17:28:21
    Description:
    The following statement descriptions are for DLC native tables, which are Iceberg tables by default. If you are using Iceberg external tables, there will be detailed differences in DDL statement. For more information, see the documentation Differences between Iceberg External and Native Table Syntax.

    CREATE TABLE

    Statement

    CREATE TABLE [ IF NOT EXISTS ] table_identifier
    ( col_name[:] col_type [ COMMENT col_comment ], ... )
    [ COMMENT table_comment ]
    [ PARTITIONED BY ( col_name1, transform(col_name2), ... ) ]

    Parameter

    table_identifier

    table_identifier supports a three-part format: catalog.db.name.

    Schemas and Data Types

    col_type
    : primitive_type
    | nested_type
    primitive_type
    : boolean
    | int/integer
    | long/bigint
    | float
    | double
    | decimal(p,s), p = maximum number of digits, s = maximum number of decimal places, s <= p <= 38
    | date
    | timestamp, timestamp with timezone. Does not support time and without timezone.
    | string, can also correspond to Iceberg uuid type.
    | binary, can also correspond to Iceberg fixed type.
    nested_type
    : struct
    | list
    | map

    Partition Transforms

    transform
    : identity, supports any type, DLC does not support this transformation.
    | bucket[N], hash mod N bucketing, supports col_type: int,long, decimal, date, timestamp, string, binary
    | truncate[L], L-truncation bucketing, supports col_type: int,long,decimal,string
    | years, year, supports col_type: date,timestamp
    | months, month, supports col_type: date,timestamp
    | days/date, date, supports col_type: date,timestamp
    | hours/date_hour, hour, supports col_type: timestamp

    Example

    CREATE TABLE dempts(
    id bigint COMMENT 'id number',
    num int,
    eno float,
    dno double,
    cno decimal(9,3),
    flag boolean,
    data string,
    ts_year timestamp,
    date_month date,
    bno binary,
    point struct<x: double, y: double>,
    points array<struct<x: double, y: double>>,
    pointmaps map<struct<x: int>, struct<a: int>>
    )
    COMMENT 'table documentation'
    PARTITIONED BY (bucket(16,id), years(ts_year), months(date_month), identity(bno), bucket(3,num),truncate(10,data));

    CREATE TABLE AS SELECT

    Statement

    CREATE TABLE [ IF NOT EXISTS ] table_identifier
    [ COMMENT table_comment ]
    [ PARTITIONED BY ( col_name1, transform(col_name2), ... ) ]
    [ TBLPROPERTIES ( property_name=property_value, ... ) ]
    AS select_statement

    Example

    CREATE TABLE dempts_copy
    COMMENT 'table create as select'
    PARTITIONED BY (eno, dno)
    AS SELECT * from dempts;

    REPLACE TABLE AS SELECT

    Generate a snapshot from the results of a SELECT query to update the table while retaining the table's history.

    Statement

    CREATE [OR REPLACE] TABLE table_identifier
    [ COMMENT table_comment ]
    [ PARTITIONED BY ( col_name1, transform(col_name2), ... ) ]
    AS select_statement

    Example

    CREATE OR REPLACE TABLE dempts_replace
    COMMENT 'table create as replace'
    PARTITIONED BY (eno, dno)
    AS SELECT * from dempts;

    DROP TABLE

    Statement

    DROP TABLE [ IF EXISTS ] table_identifier

    ALTER TABLE

    Alter table statement.

    ALTER TABLE ... RENAME TO

    Change table name.

    Statement

    ALTER TABLE table_identifier RENAME TO new_table_identifier

    ALTER TABLE ... SET / UNSET TBLPROPERTIES 

    Update/delete data table attributes.

    Statement

    -- Update attribute configuration through SET.
    ALTER TABLE table_identifier
    SET TBLPROPERTIES (property_name=property_value, ...)
    
    -- Delete attribute configuration through UNSET.
    ALTER TABLE table_identifier
    UNSET TBLPROPERTIES (property_name, ...)

    Example

    -- Update attribute configuration through SET.
    ALTER TABLE dempts SET TBLPROPERTIES ('read.split.target-size'='268435456');
    
    -- Delete attribute configuration through UNSET.
    ALTER TABLE dempts UNSET TBLPROPERTIES ('read.split.target-size'='268435456');
    

    ALTER TABLE ... WRITE ORDERED BY

    Set the sort order of the table data during insertion.

    Statement

    ALTER TABLE table_identifier 
    WRITE [LOCALLY] ORDERED BY 
    {col_name [ASC|DESC] [NULLS FIRST|LAST]}[, ...]

    Example

    ALTER TABLE dempts WRITE ORDERED BY category, id;
    
    -- use optional ASC/DEC keyword to specify sort order of each field (default ASC)
    ALTER TABLE dempts WRITE ORDERED BY category ASC, id DESC;
    
    -- use optional NULLS FIRST/NULLS LAST keyword to specify null order of each field (default FIRST)
    ALTER TABLE dempts WRITE ORDERED BY category ASC NULLS LAST, id DESC NULLS FIRST;
    
    -- To order within each task, not across tasks
    ALTER TABLE dempts WRITE LOCALLY ORDERED BY category, id;

    ALTER TABLE ... WRITE DISTRIBUTED BY PARTITION

    Modify the data distribution policy of partitioned tables.

    Statement

    ALTER TABLE table_identifier 
    WRITE DISTRIBUTED BY PARTITION 
    [ LOCALLY ORDERED BY 
    {col_name [ASC|DESC] [NULLS FIRST|LAST]}[, ...]] 

    Example

    ALTER TABLE dempts WRITE DISTRIBUTED BY PARTITION;
    ALTER TABLE dempts WRITE DISTRIBUTED BY PARTITION LOCALLY ORDERED BY id;

    ALTER TABLE COLUMNS

    Change field statement.

    ALTER TABLE ... ADD COLUMNS

    Add multiple fields.

    Statement

    -- Add multiple fields.
    ALTER TABLE table_identifier 
    ADD COLUMNS (col_name col_type [COMMENT col_comment], ...)
    
    -- Add a single field.
    ALTER TABLE table_identifier 
    ADD COLUMN col_name col_type [COMMENT col_comment] 
    [FIRST | AFTER target_col_name]

    Example

    -- Add multiple fields.
    ALTER TABLE dempts
    ADD COLUMNS (
    new_column_1 string comment 'new_column_1 docs',
    new_column_2 int comment 'new_column_2 docs'
    );
    
    -- Add a single field.
    ALTER TABLE dempts 
    ADD COLUMN new_column_3 string comment 'new_column docs';

    ALTER TABLE ... RENAME COLUMN 

    Change field name.

    Statement

    ALTER TABLE table_identifier 
    RENAME COLUMN old_column_name TO new_column_name

    ALTER TABLE ... ALTER COLUMN

    Change field type/remarks.

    Statement

    ALTER TABLE table_identifier 
    ALTER COLUMN col_name 
    {TYPE new_col_type | COMMENT col_comment}
    Currently, Iceberg TYPE changes only support type-safe field extensions:
    int/integer -> long/bigint
    float -> double
    decimal(P,S) -> decimal(P2,S), where P2 > P, indicating increased precision.

    Example

    ALTER TABLE dempts ALTER COLUMN new_column_2 TYPE bigint;
    ALTER TABLE dempts ALTER COLUMN new_column_2 comment 'alter docs';

    ALTER TABLE ... DROP COLUMN

    Delete a table field.

    Statement

    ALTER TABLE table_identifier DROP COLUMN column_name

    ALTER TABLE PARTITIONS

    ALTER TABLE ... ADD PARTITION FIELD

    Add a single partition field.

    Statement

    ALTER TABLE table_identifier 
    ADD PARTITION FIELD col_name|transform (col_name) [AS alias]
    For transform, see the <1>CREATE TABLE< 1>.

    Example

    ALTER TABLE dempts ADD PARTITION FIELD new_column_1;
    ALTER TABLE dempts ADD PARTITION FIELD bucket(3,new_column_2);

    ALTER TABLE ... REPLACE PARTITION FIELD

    Replace a single partition field.

    Statement

    ALTER TABLE table_identifier REPLACE PARTITION FIELD col_name|transform (col_name) [AS alias]

    ALTER TABLE ... DROP PARTITION FIELD

    Delete a single partition field.

    Statement

    ALTER TABLE table_identifier 
    DROP PARTITION FIELD col_name|transform (col_name);
    For transform, see the CREATE TABLE documentation.

    Example

    ALTER TABLE dempts DROP PARTITION FIELD new_column_1;
    ALTER TABLE dempts DROP PARTITION FIELD bucket(3,new_column_2);

    ALTER TABLE ... SET IDENTIFIER FIELDS 

    Add identifier fields attribute.

    Statement

    ALTER TABLE dempts SET IDENTIFIER FIELDS empno, name

    ALTER TABLE .. DROP IDENTIFIER FIELDS

    Add identifier fields attribute.

    Statement

    
    ALTER TABLE dempts DROP IDENTIFIER FIELDS empno, name
    
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support