Skip to content

Commit

Permalink
refactor(duckdb): more fine-grained extension loading and installation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jul 13, 2024
1 parent db5fc7f commit 78fe193
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import urllib
import warnings
from operator import itemgetter
from pathlib import Path
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -487,16 +486,27 @@ def _load_extensions(
) -> None:
f = self.compiler.f
query = (
sg.select(f.anon.unnest(f.list_append(C.aliases, C.extension_name)))
.from_(f.duckdb_extensions())
.where(sg.and_(C.installed, C.loaded))
sg.select(STAR)
.from_(
sg.select(
f.explode(f.list_append(C.aliases, C.extension_name)).as_("name"),
C.installed,
C.loaded,
)
.from_(f.duckdb_extensions())
.subquery()
)
.where(~sg.and_(C.installed, C.loaded), C.name.isin(*extensions))
)

with self._safe_raw_sql(query) as cur:
installed = map(itemgetter(0), cur.fetchall())
# Install and load all other extensions
todo = frozenset(extensions).difference(installed)
for extension in todo:
data = cur.fetchall()

# Install and load extensions that need it
for extension, installed, loaded in data:
if not installed or force_install:
cur.install_extension(extension, force_install=force_install)
if not loaded:
cur.load_extension(extension)

def load_extension(self, extension: str, force_install: bool = False) -> None:
Expand Down

0 comments on commit 78fe193

Please sign in to comment.