snowflake.core.iceberg_table.IcebergTableCollection¶

class snowflake.core.iceberg_table.IcebergTableCollection(schema: SchemaResource)¶

Bases: SchemaObjectCollectionParent[IcebergTableResource]

Represents the collection operations on the Snowflake Iceberg table resource.

With this collection, you can create, iterate through, and search for Iceberg tables that you have access to in the current context.

Examples

Creating an IcebergTable instance:

>>> iceberg_tables = root.databases["my_db"].schemas["my_schema"].iceberg_tables
>>> new_iceberg_table = IcebergTable(
...     name="name",
...     columns=[IcebergTableColumn(name="col1", datatype="string")],
... )
>>> iceberg_tables.create(new_iceberg_table)
Copy

Attributes

database¶
root¶

Methods

create(iceberg_table: IcebergTable, *, copy_grants: bool | None = False, mode: CreateMode = CreateMode.error_if_exists) → IcebergTableResource¶
create(iceberg_table: IcebergTable, *, as_select: str | None = None, copy_grants: bool | None = False, mode: CreateMode = CreateMode.error_if_exists) → IcebergTableResource
create(iceberg_table: IcebergTable, *, like: str, copy_grants: bool | None = False, mode: CreateMode = CreateMode.error_if_exists) → IcebergTableResource
create(iceberg_table: IcebergTable, *, from_aws_glue_catalog: Literal[True] = True, mode: CreateMode = CreateMode.error_if_exists) → IcebergTableResource
create(iceberg_table: IcebergTable, *, from_delta: Literal[True] = True, mode: CreateMode = CreateMode.error_if_exists) → IcebergTableResource
create(iceberg_table: IcebergTable, *, from_iceberg_files: Literal[True] = True, mode: CreateMode = CreateMode.error_if_exists) → IcebergTableResource
create(iceberg_table: IcebergTable, *, from_iceberg_rest: Literal[True] = True, mode: CreateMode = CreateMode.error_if_exists) → IcebergTableResource
create(iceberg_table: IcebergTable, *, clone_iceberg_table: str | Clone, copy_grants: bool | None = False, mode: CreateMode = CreateMode.error_if_exists) → IcebergTableResource

Create an Iceberg table in Snowflake.

There are multiple ways to create an Iceberg table:
  • by building from scratch

  • by creating from select query

  • by creating it from AWS Glue Catalog or Delta catalog

  • by creating it from files

  • by creating it from REST API

  • by cloning existing table

Parameters:
  • iceberg_table (Union[IcebergTable, str]) – The new Iceberg table’s name.

  • as_select (str) – Creates an Iceberg table using a select query.

  • like (str) – Create a new Iceberg table like the specified one, but empty.

  • from_aws_glue_catalog (IcebergTableFromAwsGlueCatalog) – Creates an Iceberg table from AWS Glue Catalog.

  • from_delta (IcebergTableFromDelta) – Creates an Iceberg table from Delta.

  • from_iceberg_files (IcebergTableFromIcebergFiles) – Creates an Iceberg table using Iceberg files in object storage (external cloud storage).

  • from_iceberg_rest (IcebergTableFromIcebergRest) – Creates an Iceberg in Iceberg REST catalog.

  • clone_iceberg_table (str or Clone object) – The name of Iceberg table to be cloned, or a Clone object which would contain the name of the Iceberg table with support to clone at a specific time.

  • copy_grants (bool, optional) – Copy grants when resource is created.

  • mode (CreateMode, optional) –

    One of the following enum values:

    CreateMode.error_if_exists: Throw an snowflake.core.exceptions.ConflictError if the Iceberg table already exists in Snowflake. Equivalent to SQL create Iceberg table <name> ....

    CreateMode.or_replace: Replace if the Iceberg table already exists in Snowflake. Equivalent to SQL create or replace Iceberg table <name> ....

    CreateMode.if_not_exists: Do nothing if the Iceberg table already exists in Snowflake. Equivalent to SQL create Iceberg table <name> if not exists...

    Default is CreateMode.error_if_exists.

Examples

Creating an Iceberg table, replacing any existing Iceberg table with the same name:

>>> iceberg_tables = root.databases["my_db"].schemas["my_schema"].iceberg_tables
>>> new_iceberg_table = IcebergTable(
...     name="name",
...     columns=[IcebergTableColumn(name="col1", datatype="string")],
... )
>>> iceberg_tables.create(new_iceberg_table, mode=CreateMode.or_replace)
Copy

Cloning an Iceberg table instance:

>>> iceberg_tables = root.databases["my_db"].schemas["my_schema"].iceberg_tables
>>> iceberg_tables.create(
...     IcebergTable(name="new_table"),
...     clone_iceberg_table="iceberg_table_name_to_be_cloned",
...     mode=CreateMode.if_not_exists,
... )
Copy
items() → ItemsView[str, T]¶
iter(*, like: Annotated[str, Strict(strict=True)] | None = None, starts_with: Annotated[str, Strict(strict=True)] | None = None, show_limit: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=1), Le(le=10000)])] | None = None, from_name: Annotated[str, Strict(strict=True)] | None = None) → Iterator[IcebergTable]¶

Iterate through IcebergTable objects from Snowflake, filtering on any optional ‘like’ pattern.

Parameters:
  • like (str, optional) – A case-insensitive string functioning as a filter, with support for SQL wildcard characters (% and _).

  • starts_with (str, optional) – String used to filter the command output based on the string of characters that appear at the beginning of the object name. Uses case-sensitive pattern matching.

  • show_limit (int, optional) – Limit of the maximum number of rows returned by iter(). The default is None, which behaves equivalently to show_limit=10000. This value must be between 1 and 10000.

  • from_name (str, optional) – Fetch rows only following the first row whose object name matches the specified string. This is case-sensitive and does not have to be the full name.

Examples

Showing all Iceberg tables that you have access to see:

>>> iceberg_tables = iceberg_table_collection.iter()
Copy

Showing information of the exact Iceberg table you want to see:

>>> iceberg_tables = iceberg_table_collection.iter(like="your-iceberg-table-name")
Copy

Showing Iceberg tables starting with ‘your-iceberg-table-name-‘:

>>> iceberg_tables = iceberg_table_collection.iter(like="your-iceberg-table-name-%")
Copy

Using a for loop to retrieve information from iterator:

>>> for iceberg_table in iceberg_tables:
...     print(iceberg_table.name)
Copy
keys() → KeysView[str]¶
values() → ValuesView[T]¶