Transactions#

class ducklake.transaction.Transaction[source]#

Methods:

create_table

Create a new table as part of this transaction.

create_table(
name: str | tuple[str, str] | TableName,
schema: Schema | Sequence[Column] | Mapping[str, DataType],
partition_by: Partitioning | Sequence[PartitionColumn] | Sequence[str] | PartitionColumn | str | None = None,
data_path: str | None = None,
tags: Mapping[str, str] | None = None,
) TransactionTable[source]#

Create a new table as part of this transaction.

The table (and any subsequent changes or writes against it) only becomes visible once the transaction is committed.

Parameters:
  • name – The fully qualified name of the new table.

  • schema – The schema of the new table.

  • partition_by – Optional partitioning for the table.

  • data_path – Optional data path for the table.

  • tags – Optional tags to attach to the table.

Returns:

A TransactionTable referring to the newly created table.

class ducklake.transaction.TransactionTable[source]#

Methods:

add_column

Add a new column to the table.

add_column_tag

Add a new tag to a column.

add_tag

Add a new tag to the table.

delete

Delete the table from the catalog.

remove_column

Remove a column from the table.

remove_column_tag

Remove an existing tag from a column.

remove_tag

Remove an existing tag from the table.

rename

Rename the table in the catalog.

rename_column

Rename a column in the table.

update_column_default

Update the default value of a column.

update_column_dtype

Update the data type of the provided column.

update_column_nullability

Update the nullability of a column.

update_partitioning

Update the partitioning of this table.

update_schema

Update the full schema of the table.

Attributes:

partitioning

The partitioning of the table, if any.

schema

The schema of the table.

add_column(column: Column) None[source]#

Add a new column to the table.

Parameters:

column – The column to add.

add_column_tag(
column: str | Sequence[str],
key: str,
value: str,
) None[source]#

Add a new tag to a column.

Parameters:
  • column – The name of the column to add the tag to. This may be provided as a “path” to a nested column.

  • key – The key of the tag.

  • value – The value of the tag.

add_tag(key: str, value: str) None[source]#

Add a new tag to the table.

Parameters:
  • key – The key of the tag.

  • value – The value of the tag.

delete() None[source]#

Delete the table from the catalog.

After calling this method, the TransactionTable object is no longer valid.

property partitioning: Partitioning | None#

The partitioning of the table, if any.

remove_column(column: str | Sequence[str]) None[source]#

Remove a column from the table.

Parameters:

column – The name of the column to remove. This may be provided as a “path” to a nested column.

remove_column_tag(column: str | Sequence[str], key: str) None[source]#

Remove an existing tag from a column.

Parameters:
  • column – The name of the column to remove the tag from. This may be provided as a “path” to a nested column.

  • key – The key of the tag.

Raises:

ValueError – If no tag for the provided key exists.

remove_tag(key: str) None[source]#

Remove an existing tag from the table.

Parameters:

key – The key of the tag.

Raises:

ValueError – If no tag for the provided key exists.

rename(new_name: str) None[source]#

Rename the table in the catalog.

Parameters:

new_name – The new name for the table.

Note

This operation does not affect the schema the table resides in. It is not currently possible to move a table to a different schema.

rename_column(column: str | Sequence[str], new_name: str) None[source]#

Rename a column in the table.

Parameters:
  • column – The current name of the column to rename. This may be provided as a “path” to a nested column.

  • new_name – The new name for the column.

property schema: Schema#

The schema of the table.

update_column_default(
column: str,
default_value: Value | tuple[str, str] | None = None,
) None[source]#

Update the default value of a column.

The default value can be a literal value, or an expression specified as a (dialect, expression) tuple. Pass None to remove the default.

Parameters:
  • column – The column for which to change the default value.

  • default_value – The new default value.

update_column_dtype(
column: str,
new_dtype: DataType,
) None[source]#

Update the data type of the provided column.

Generally speaking, data types can only be changed via type promotion. For example, integers can be turned into larger integers.

For struct columns, updating the data type allows adding and dropping fields.

Parameters:
  • column – The column for which to change the data type.

  • new_dtype – The new data type of the column.

update_column_nullability(column: str, nullable: bool) None[source]#

Update the nullability of a column.

Parameters:
  • column – The column for which to change the nullability.

  • nullable – Whether the column should allow null values.

update_partitioning(
partitioning: Partitioning | None,
) None[source]#

Update the partitioning of this table.

Parameters:

partitioning – The new partitioning. If None is provided, the partitioning of the table is reset.

Note

This is a metadata-only operation which does not rewrite data files. As a result, queries might not be fully optimized.

update_schema(schema: Schema) None[source]#

Update the full schema of the table.

This is a convenience function that allows to easily add and remove multiple columns as well as changing the data type of existing columns.

Parameters:

schema – The new schema of the table.