Skip to content

refactor(datafusion): avoid reinitializing memtables on every execute call #10057

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

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
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
17 changes: 9 additions & 8 deletions ibis/backends/datafusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import datafusion as df
import pyarrow as pa
import pyarrow.dataset as ds
import pyarrow_hotfix # noqa: F401
import sqlglot as sg
import sqlglot.expressions as sge
Expand Down Expand Up @@ -418,14 +417,16 @@ def _register_failure(self):

def _register_in_memory_table(self, op: ops.InMemoryTable) -> None:
name = op.name
schema = op.schema

self.con.deregister_table(name)
if batches := op.data.to_pyarrow(schema).to_batches():
self.con.register_record_batches(name, [batches])
else:
empty_dataset = ds.dataset([], schema=schema.to_pyarrow())
self.con.register_dataset(name=name, dataset=empty_dataset)
db = self.con.catalog().database()

try:
db.table(name)
except Exception: # noqa: BLE001 because datafusion doesn't have anything better
# self.con.register_table is broken, so we do this roundabout thing
# of constructing a datafusion DataFrame, which has a side effect
# of registering the table
self.con.from_arrow_table(op.data.to_pyarrow(op.schema), name)

def read_csv(
self, path: str | Path, table_name: str | None = None, **kwargs: Any
Expand Down