|
47 | 47 | DOWNCAST_NS_TIMESTAMP_TO_US_ON_WRITE, |
48 | 48 | CommitTableResponse, |
49 | 49 | CreateTableTransaction, |
| 50 | + ReplaceTableTransaction, |
50 | 51 | StagedTable, |
51 | 52 | Table, |
52 | 53 | TableProperties, |
@@ -442,6 +443,66 @@ def create_table_if_not_exists( |
442 | 443 | except TableAlreadyExistsError: |
443 | 444 | return self.load_table(identifier) |
444 | 445 |
|
| 446 | + @abstractmethod |
| 447 | + def replace_table( |
| 448 | + self, |
| 449 | + identifier: str | Identifier, |
| 450 | + schema: Schema | pa.Schema, |
| 451 | + location: str | None = None, |
| 452 | + partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC, |
| 453 | + sort_order: SortOrder = UNSORTED_SORT_ORDER, |
| 454 | + properties: Properties = EMPTY_DICT, |
| 455 | + ) -> Table: |
| 456 | + """Atomically replace a table's schema, spec, sort order, location, and properties. |
| 457 | +
|
| 458 | + The table UUID and history (snapshots, schemas, specs, sort orders) are preserved. |
| 459 | + The current snapshot is cleared (main branch ref is removed). |
| 460 | +
|
| 461 | + Args: |
| 462 | + identifier (str | Identifier): Table identifier. |
| 463 | + schema (Schema): New table schema. |
| 464 | + location (str | None): New table location. Defaults to the existing location. |
| 465 | + partition_spec (PartitionSpec): New partition spec. |
| 466 | + sort_order (SortOrder): New sort order. |
| 467 | + properties (Properties): New table properties (merged with existing). |
| 468 | +
|
| 469 | + Returns: |
| 470 | + Table: the replaced table instance. |
| 471 | +
|
| 472 | + Raises: |
| 473 | + NoSuchTableError: If the table does not exist. |
| 474 | + """ |
| 475 | + |
| 476 | + @abstractmethod |
| 477 | + def replace_table_transaction( |
| 478 | + self, |
| 479 | + identifier: str | Identifier, |
| 480 | + schema: Schema | pa.Schema, |
| 481 | + location: str | None = None, |
| 482 | + partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC, |
| 483 | + sort_order: SortOrder = UNSORTED_SORT_ORDER, |
| 484 | + properties: Properties = EMPTY_DICT, |
| 485 | + ) -> ReplaceTableTransaction: |
| 486 | + """Create a ReplaceTableTransaction. |
| 487 | +
|
| 488 | + The transaction can be used to stage additional changes (schema evolution, |
| 489 | + partition evolution, etc.) before committing. |
| 490 | +
|
| 491 | + Args: |
| 492 | + identifier (str | Identifier): Table identifier. |
| 493 | + schema (Schema): New table schema. |
| 494 | + location (str | None): New table location. Defaults to the existing location. |
| 495 | + partition_spec (PartitionSpec): New partition spec. |
| 496 | + sort_order (SortOrder): New sort order. |
| 497 | + properties (Properties): New table properties (merged with existing). |
| 498 | +
|
| 499 | + Returns: |
| 500 | + ReplaceTableTransaction: A transaction for the replace operation. |
| 501 | +
|
| 502 | + Raises: |
| 503 | + NoSuchTableError: If the table does not exist. |
| 504 | + """ |
| 505 | + |
445 | 506 | @abstractmethod |
446 | 507 | def load_table(self, identifier: str | Identifier) -> Table: |
447 | 508 | """Load the table's metadata and returns the table instance. |
@@ -888,6 +949,28 @@ def create_table_transaction( |
888 | 949 | self._create_staged_table(identifier, schema, location, partition_spec, sort_order, properties) |
889 | 950 | ) |
890 | 951 |
|
| 952 | + def replace_table( |
| 953 | + self, |
| 954 | + identifier: str | Identifier, |
| 955 | + schema: Schema | pa.Schema, |
| 956 | + location: str | None = None, |
| 957 | + partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC, |
| 958 | + sort_order: SortOrder = UNSORTED_SORT_ORDER, |
| 959 | + properties: Properties = EMPTY_DICT, |
| 960 | + ) -> Table: |
| 961 | + raise NotImplementedError("replace_table is not yet supported for this catalog type") |
| 962 | + |
| 963 | + def replace_table_transaction( |
| 964 | + self, |
| 965 | + identifier: str | Identifier, |
| 966 | + schema: Schema | pa.Schema, |
| 967 | + location: str | None = None, |
| 968 | + partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC, |
| 969 | + sort_order: SortOrder = UNSORTED_SORT_ORDER, |
| 970 | + properties: Properties = EMPTY_DICT, |
| 971 | + ) -> ReplaceTableTransaction: |
| 972 | + raise NotImplementedError("replace_table_transaction is not yet supported for this catalog type") |
| 973 | + |
891 | 974 | def table_exists(self, identifier: str | Identifier) -> bool: |
892 | 975 | try: |
893 | 976 | self.load_table(identifier) |
|
0 commit comments