Skip to main content

Overview

Iceberg uses Apache Spark’s DataSourceV2 API for catalog implementations. To use Iceberg DDL commands, first configure Spark catalogs.

CREATE TABLE

Spark 3+ can create tables in any Iceberg catalog using the USING iceberg clause:

Table Options

Table create commands support the full range of Spark create clauses:
  • PARTITIONED BY (partition-expressions) - Configure partitioning
  • LOCATION '(fully-qualified-uri)' - Set table location
  • COMMENT 'table documentation' - Add table description
  • TBLPROPERTIES ('key'='value', ...) - Set table configuration
CREATE TABLE ... LIKE ... syntax is not supported.

Partitioned Tables

Create partitioned tables using PARTITIONED BY:

Partition Transforms

Iceberg supports the following partition transforms:
For strings, truncate limits to the given length. For integers and longs, it creates bins: truncate(10, i) produces partitions 0, 10, 20, 30, etc.

CREATE TABLE AS SELECT (CTAS)

Create tables populated with query results:
CTAS is atomic when using SparkCatalog, but not atomic when using SparkSessionCatalog.

REPLACE TABLE AS SELECT (RTAS)

Atomically replace table contents while preserving history:
The schema and partition spec will be replaced if changed. To avoid modifying the schema, use INSERT OVERWRITE instead.

DROP TABLE

Drop behavior changed in Iceberg 0.14:
  • Before 0.14: DROP TABLE deleted table metadata and contents
  • From 0.14: DROP TABLE only removes from catalog; use DROP TABLE PURGE to delete contents

Remove from Catalog Only

Remove from Catalog and Delete Contents

ALTER TABLE

Iceberg provides full ALTER TABLE support in Spark 3:
  • Rename tables
  • Set or remove table properties
  • Add, delete, and rename columns
  • Add, delete, and rename nested fields
  • Reorder columns
  • Widen numeric types
  • Change column nullability

Rename Table

Table Properties

Add Columns

For arrays and maps, use element and value keywords to access nested columns:
  • ADD COLUMN points.element.z double - Add field to array element
  • ADD COLUMN points.value.b int - Add field to map value

Rename Columns

Nested rename only affects the leaf field. Renaming location.lat to latitude results in location.latitude.

Alter Column Type and Properties

Safe type widening is supported:
Safe type conversions:
  • intbigint
  • floatdouble
  • decimal(P,S)decimal(P2,S) where P2 > P
  • Cannot change nullable column to non-nullable with SET NOT NULL
  • Use ADD COLUMN and DROP COLUMN for struct type changes

Drop Columns

SQL Extensions

The following commands require Iceberg SQL extensions.

Partition Evolution

Dynamic partition overwrite behavior changes when partitioning changes. For example, moving from daily to hourly partitions will cause overwrites to affect hourly partitions instead of daily ones.

Write Ordering

Configure automatic data sorting for writes:

Identifier Fields

Identifier fields must be NOT NULL columns. Setting identifier fields enables Flink upsert operations.

Branching and Tagging

Iceberg Views

Iceberg views require Spark 3.4+.

Create View

Manage Views

Next Steps

Query Data

Learn about SELECT queries and time travel

Write Data

Master INSERT, MERGE, and UPDATE operations

Configuration

Configure Spark catalogs and options

Procedures

Maintain tables with stored procedures