Skip to content

Commit

Permalink
refactor: delete unused schemas cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Aug 3, 2023
1 parent 14cf8ac commit 0b6e0d9
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions ibis/backends/base/sql/alchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def _current_schema(self) -> str | None:
def do_connect(self, con: sa.engine.Engine) -> None:
self.con = con
self._inspector = None
self._schemas: dict[str, sch.Schema] = {}
self._temp_views: set[str] = set()

@property
Expand Down Expand Up @@ -295,8 +294,6 @@ def create_table(
if schema is None:
schema = obj.schema()

self._schemas[self._fully_qualified_name(name, database)] = schema

if has_expr := obj is not None:
# this has to happen outside the `begin` block, so that in-memory
# tables are visible inside the transaction created by it
Expand Down Expand Up @@ -430,12 +427,6 @@ def drop_table(
with self.begin() as bind:
t.drop(bind=bind, checkfirst=force)

qualified_name = self._fully_qualified_name(name, database)

with contextlib.suppress(KeyError):
# schemas won't be cached if created with raw_sql
del self._schemas[qualified_name]

def truncate_table(self, name: str, database: str | None = None) -> None:
t = self._get_sqla_table(name, schema=database)
with self.begin() as con:
Expand Down Expand Up @@ -494,39 +485,26 @@ def _get_sqla_table(
return table
return self._handle_failed_column_type_inference(table, nulltype_cols)

# TODO(kszucs): remove the schema parameter
@classmethod
def _schema_from_sqla_table(
cls,
table: sa.sql.TableClause,
schema: sch.Schema | None = None,
) -> sch.Schema:
def _schema_from_sqla_table(cls, table: sa.sql.TableClause) -> sch.Schema:
"""Retrieve an ibis schema from a SQLAlchemy `Table`.
Parameters
----------
table
Table whose schema to infer
schema
Predefined ibis schema to pull types from
dialect
Optional sqlalchemy dialect
Returns
-------
schema
An ibis schema corresponding to the types of the columns in `table`.
"""
schema = schema if schema is not None else {}
pairs = []
for column in table.columns:
name = column.name
if name in schema:
dtype = schema[name]
else:
dtype = cls.compiler.translator_class.get_ibis_type(
column.type, nullable=column.nullable
)
dtype = cls.compiler.translator_class.get_ibis_type(
column.type, nullable=column.nullable
)
pairs.append((name, dtype))
return sch.schema(pairs)

Expand Down Expand Up @@ -613,9 +591,7 @@ def table(

sqla_table = self._get_sqla_table(name, schema=schema)

schema = self._schema_from_sqla_table(
sqla_table, schema=self._schemas.get(name)
)
schema = self._schema_from_sqla_table(sqla_table)
node = ops.DatabaseTable(
name=name, schema=schema, source=self, namespace=namespace
)
Expand Down

0 comments on commit 0b6e0d9

Please sign in to comment.