CREATE TABLE

To create an MixedFormat table under an Amoro Catalog, you can use USING ARCTIC to specify the provider in the CREATE TABLE statement. If the Catalog type is Hive, the created table will be a Hive-compatible table.

  1. CREATE TABLE arctic_catalog.db.sample (
  2. id bigint COMMENT "unique id",
  3. data string
  4. ) USING arctic

PRIMARY KEY

You can use PRIMARY KEY in the CREATE TABLE statement to specify the primary key column. MixedFormat ensures the uniqueness of the primary key column through MOR (Merge on Read) and Self-Optimizing.

  1. CREATE TABLE arctic_catalog.db.sample (
  2. id bigint COMMENT "unique id",
  3. data string ,
  4. PRIMARY KEY (id)
  5. ) USING arctic

PARTITIONED BY

Using PARTITIONED BY in the CREATE TABLE statement to create a table with partition spec.

  1. CREATE TABLE arctic_catalog.db.sample (
  2. id bigint,
  3. data string,
  4. category string)
  5. USING arctic
  6. PARTITIONED BY (category)

In the PARTITIONED BY clause, you can define partition expressions, and Mixed-Iceberg format supports all partition expressions in Iceberg.

  1. CREATE TABLE arctic_catalog.db.sample (
  2. id bigint,
  3. data string,
  4. category string,
  5. ts timestamp,
  6. PRIMARY KEY (id) )
  7. USING arctic
  8. PARTITIONED BY (bucket(16, id), days(ts), category)

Supported transformations are:

  • years(ts): partition by year
  • months(ts): partition by month
  • days(ts) or date(ts): equivalent to dating partitioning
  • hours(ts) or date_hour(ts): equivalent to dating and hour partitioning
  • bucket(N, col): partition by hashed value mod N buckets
  • truncate(L, col): partition by value truncated to L

    Strings are truncated to the given length

    Integers and longs truncate to bins: truncate(10, i) produces partitions 0, 10, 20, 30, …

Mixed-Hive format doesn’t support transform.

CREATE TABLE … AS SELECT

  1. CREATE TABLE arctic_catalog.db.sample
  2. USING arctic
  3. AS SELECT ...

The CREATE TABLE ... AS SELECT syntax is used to create a table and write the query results to the table. Primary keys, partitions, and properties are not inherited from the source table and need to be configured separately.

You can enable uniqueness check for the primary key in the source table by setting set spark.sql.arctic.check-source-data-uniqueness.enabled = true in Spark SQL. If there are duplicate primary keys, an error will be raised during the write operation.

You can use the following syntax to create a table with primary keys, partitions, and properties:

  1. CREATE TABLE arctic_catalog.db.sample
  2. PRIMARY KEY(id) USING arctic
  3. PARTITIONED BY (pt)
  4. TBLPROPERTIES (''prop1''=''val1'', ''prop2''=''val2'')
  5. AS SELECT ...

In the current version, CREATE TABLE ... AS SELECT does not provide atomicity guarantees.

CREATE TABLE … LIKE

The CREATE TABLE ... LIKE syntax copies the structure of a table, including primary keys and partitions, to a new table, but it does not copy the data.

  1. USE arctic_catalog;
  2. CREATE TABLE db.sample
  3. LIKE db.sample2
  4. USING arctic
  5. TBLPROPERTIES ('owner'='xxxx');

Since PRIMARY KEY is not a standard Spark syntax, if the source table is a MixedFormat table with primary keys, the new table can copy the schema information with the primary keys. Otherwise, only schema could be copied.

Create Table Like only supports the binary form of db.table and in the same catalog

REPLACE TABLE … AS SELECT

The REPLACE TABLE ... AS SELECT syntax only supports tables without primary keys in the current version.

  1. REPLACE TABLE arctic_catalog.db.sample
  2. USING arctic
  3. AS SELECT ...

In the current version, REPLACE TABLE ... AS SELECT does not provide atomicity guarantees.

DROP TABLE

  1. DROP TABLE arctic_catalog.db.sample;

TRUNCATE TABLE

The TRUNCATE TABLE statement could delete all data in the table.

  1. TRUNCATE TABLE arctic_catalog.db.sample;

ALTER TABLE

The ALTER TABLE syntax supported by Mixed-Format includes:

  • ALTER TABLE … SET TBLPROPERTIES
  • ALTER TABLE … ADD COLUMN
  • ALTER TABLE … RENAME COLUMN
  • ALTER TABLE … ALTER COLUMN
  • ALTER TABLE … DROP COLUMN
  • ALTER TABLE … DROP PARTITION

ALTER TABLE … SET TBLPROPERTIES

  1. ALTER TABLE arctic_catalog.db.sample SET TBLPROPERTIES (
  2. 'read.split.target-size'='268435456'
  3. );

Using UNSET to remove properties:

  1. ALTER TABLE arctic_catalog.db.sample UNSET TBLPROPERTIES ('read.split.target-size');

ALTER TABLE … ADD COLUMN

  1. ALTER TABLE arctic_catalog.db.sample
  2. ADD COLUMNS (
  3. new_column string comment 'new_column docs'
  4. );

You can add multiple columns at once, separated by commas.

  1. -- create a struct column
  2. ALTER TABLE arctic_catalog.db.sample
  3. ADD COLUMN point struct<x: double, y: double>;
  4. -- add a field to the struct
  5. ALTER TABLE arctic_catalog.db.sample
  6. ADD COLUMN point.z double;
  1. -- create a nested array column of struct
  2. ALTER TABLE arctic_catalog.db.sample
  3. ADD COLUMN points array<struct<x: double, y: double>>;
  4. -- add a field to the struct within an array. Using keyword 'element' to access the array's element column.
  5. ALTER TABLE arctic_catalog.db.sample
  6. ADD COLUMN points.element.z double;
  1. -- create a map column of struct key and struct value
  2. ALTER TABLE arctic_catalog.db.sample
  3. ADD COLUMN points map<struct<x: int>, struct<a: int>>;
  4. -- add a field to the value struct in a map. Using keyword 'value' to access the map's value column.
  5. ALTER TABLE arctic_catalog.db.sample
  6. ADD COLUMN points.value.b int;

You can add columns at any position by using the FIRST or AFTER clause.

  1. ALTER TABLE arctic_catalog.db.sample
  2. ADD COLUMN new_column bigint AFTER other_column;
  1. ALTER TABLEarctic_catalog.db.sample
  2. ADD COLUMN nested.new_column bigint FIRST;

ALTER TABLE … RENAME COLUMN

  1. ALTER TABLE arctic_catalog.db.sample RENAME COLUMN data TO payload;

ALTER TABLE … ALTER COLUMN

"ALTER COLUMN` can be used to widen types, make fields nullable, set comments, and reorder fields.

  1. ALTER TABLE arctic_catalog.db.sample ALTER COLUMN measurement TYPE double;

To add or remove columns from a structure, use ADD COLUMN or DROP COLUMN with nested column names.

Column comments can also be updated using ALTER COLUMN.

  1. ALTER TABLE arctic_catalog.db.sample ALTER COLUMN measurement TYPE double COMMENT 'unit is bytes per second';
  2. ALTER TABLE arctic_catalog.db.sample ALTER COLUMN measurement COMMENT 'unit is kilobytes per second';

You can use the FIRST and AFTER clauses to reorder top-level or nested columns within a structure.

  1. ALTER TABLE arctic_catalog.db.sample ALTER COLUMN col FIRST;
  1. ALTER TABLE arctic_catalog.db.sample ALTER COLUMN nested.col AFTER other_col;

ALTER TABLE … DROP COLUMN

  1. ALTER TABLE arctic_catalog.db.sample DROP COLUMN id;
  2. ALTER TABLE arctic_catalog.db.sample DROP COLUMN point.z;

ALTER TABLE … DROP PARTITION

  1. ALTER TABLE arctic_catalog.db.sample DROP IF EXISTS PARTITION (dt=2022);

DESC TABLE

DESCRIBE TABLE returns basic metadata information about a table, including the primary key information for tables that have a primary key

  1. { DESC | DESCRIBE } TABLE arctic_catalog.db.sample;