Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to allow disabling creation of catalog tables #1155

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions pyiceberg/catalog/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
union,
update,
)
from sqlalchemy.exc import IntegrityError, NoResultFound, OperationalError, ProgrammingError
from sqlalchemy.exc import IntegrityError, NoResultFound
from sqlalchemy.orm import (
DeclarativeBase,
Mapped,
Expand Down Expand Up @@ -126,20 +126,8 @@ def __init__(self, name: str, **properties: str):

self.engine = create_engine(uri_prop, echo=echo, pool_pre_ping=pool_pre_ping)

self._ensure_tables_exist()

def _ensure_tables_exist(self) -> None:
with Session(self.engine) as session:
for table in [IcebergTables, IcebergNamespaceProperties]:
stmt = select(1).select_from(table)
try:
session.scalar(stmt)
except (
OperationalError,
ProgrammingError,
): # sqlalchemy returns OperationalError in case of sqlite and ProgrammingError with postgres.
self.create_tables()
return
# Only creates tables that do not exist
self.create_tables()

def create_tables(self) -> None:
SqlCatalogBaseTable.metadata.create_all(self.engine)
Expand Down