Skip to content

Executing statements in Iceberg

Use Iceberg.execute(...) to execute DDL and DML operations.

Warning

In DML/DDL queries table names must include catalog prefix.

Syntax support

This method supports any query syntax supported by Iceberg (Spark SQL), like:

  • ✅︎ CREATE TABLE ..., CREATE VIEW ...
  • ✅︎ INSERT INTO ... SELECT ..., MERGE INTO ...
  • ✅︎ ALTER TABLE ... ADD COLUMN, ALTER TABLE ... DROP COLUMN
  • ✅︎ DROP TABLE ..., DROP VIEW ...
  • ✅︎ REPLACE TABLE ...
  • ✅︎ other statements supported by Iceberg
  • SET ...; SELECT ...; - multiple statements not supported

Examples

from onetl.connection import Iceberg

iceberg = Iceberg(catalog_name="my_catalog", ...)

iceberg.execute("DROP TABLE my_catalog.my_schema.my_table")
iceberg.execute(
    """
    CREATE TABLE my_catalog.my_schema.my_table (
        id BIGINT,
        key STRING,
        value DOUBLE
    )
    USING iceberg
    """,
)

Details

Execute DDL or DML statement. support hooks

Parameters:

  • statement (str) –

    Statement to be executed.