Skip to content

Commit de9c1b2

Browse files
committed
fix(glue): Extract S3 Tables connection type constant and simplify _create_table_s3tables signature
- Extract "aws:s3tables" string literal into GLUE_CONNECTION_S3_TABLES constant - Remove redundant database_name/table_name params from _create_table_s3tables; derive them from identifier inside the method instead
1 parent 4f9299e commit de9c1b2

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

pyiceberg/catalog/glue.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
GLUE_SESSION_TOKEN = "glue.session-token"
131131
GLUE_MAX_RETRIES = "glue.max-retries"
132132
GLUE_RETRY_MODE = "glue.retry-mode"
133+
GLUE_CONNECTION_S3_TABLES = "aws:s3tables"
133134

134135
MAX_RETRIES = 10
135136
STANDARD_RETRY_MODE = "standard"
@@ -438,13 +439,11 @@ def _is_s3tables_database(self, database_name: str) -> bool:
438439
return False
439440
database = database_response["Database"]
440441
federated = database.get("FederatedDatabase", {})
441-
return (federated.get("ConnectionType") or "").lower() == "aws:s3tables"
442+
return (federated.get("ConnectionType") or "").lower() == GLUE_CONNECTION_S3_TABLES
442443

443444
def _create_table_s3tables(
444445
self,
445446
identifier: str | Identifier,
446-
database_name: str,
447-
table_name: str,
448447
schema: Union[Schema, "pa.Schema"],
449448
location: str | None,
450449
partition_spec: PartitionSpec,
@@ -463,6 +462,8 @@ def _create_table_s3tables(
463462
464463
On failure, the table created in step 1 is deleted.
465464
"""
465+
database_name, table_name = self.identifier_to_database_and_table(identifier)
466+
466467
if location is not None:
467468
raise ValueError(
468469
f"Cannot specify a location for S3 Tables table {database_name}.{table_name}. "
@@ -559,8 +560,6 @@ def create_table(
559560
if self._is_s3tables_database(database_name):
560561
return self._create_table_s3tables(
561562
identifier=identifier,
562-
database_name=database_name,
563-
table_name=table_name,
564563
schema=schema,
565564
location=location,
566565
partition_spec=partition_spec,

tests/catalog/test_glue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import pytest
2222
from moto import mock_aws
2323

24-
from pyiceberg.catalog.glue import GlueCatalog
24+
from pyiceberg.catalog.glue import GLUE_CONNECTION_S3_TABLES, GlueCatalog
2525
from pyiceberg.exceptions import (
2626
NamespaceAlreadyExistsError,
2727
NamespaceNotEmptyError,
@@ -1013,7 +1013,7 @@ def _create_s3tables_database(catalog: GlueCatalog, database_name: str) -> None:
10131013
"Name": database_name,
10141014
"FederatedDatabase": {
10151015
"Identifier": "arn:aws:s3tables:us-east-1:123456789012:bucket/my-bucket",
1016-
"ConnectionType": "aws:s3tables",
1016+
"ConnectionType": GLUE_CONNECTION_S3_TABLES,
10171017
},
10181018
}
10191019
)

0 commit comments

Comments
 (0)