Skip to content

Commit

Permalink
fix(oracle): clean up memtables at exit
Browse files Browse the repository at this point in the history
Two issues in one!
First, need to register memtables as temp tables, also need to make sure
they're cleaned up at exit.
  • Loading branch information
gforsyth authored and kszucs committed Feb 12, 2024
1 parent 1dffd5e commit dc34f61
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ibis/backends/oracle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import atexit
import contextlib
import re
import warnings
Expand Down Expand Up @@ -385,11 +386,12 @@ def _register_in_memory_table(self, op: ops.InMemoryTable) -> None:
for colname, typ in schema.items()
]

create_stmt = sg.exp.Create(
create_stmt = sge.Create(
kind="TABLE",
this=sg.exp.Schema(
this=sg.to_identifier(name, quoted=quoted), expressions=column_defs
),
properties=sge.Properties(expressions=[sge.TemporaryProperty()]),
).sql(self.name, pretty=True)

data = op.data.to_frame().itertuples(index=False)
Expand All @@ -401,6 +403,8 @@ def _register_in_memory_table(self, op: ops.InMemoryTable) -> None:
for row in data:
cur.execute(insert_stmt, row)

atexit.register(self._clean_up_tmp_table, name)

def _metadata(self, query: str) -> Iterable[tuple[str, dt.DataType]]:
name = util.gen_name("oracle_metadata")
dialect = self.name
Expand Down

0 comments on commit dc34f61

Please sign in to comment.