Skip to content

Commit

Permalink
Set memory limit in duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Dec 25, 2023
1 parent 6fd2afd commit e092c73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@
import duckdb
from hdx.data.dataset import Dataset

from src.config import HDX_MAINTAINER, HDX_OWNER_ORG, HDX_URL_PREFIX
from src.config import (
DUCK_DB_MEMORY_LIMIT,
HDX_MAINTAINER,
HDX_OWNER_ORG,
HDX_URL_PREFIX,
)


global LOCAL_CON_POOL
Expand Down Expand Up @@ -1124,6 +1129,9 @@ def __init__(self, db_path):
con.install_extension("json")
con.load_extension("spatial")
con.load_extension("json")
if DUCK_DB_MEMORY_LIMIT:
con.sql(f"""SET memory_limit = '{DUCK_DB_MEMORY_LIMIT}'""")
con.sql("""SET enable_progress_bar = true""")

def run_query(self, query, attach_pgsql=False, load_spatial=False):
"""
Expand Down
4 changes: 4 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
or config.get("HDX", "ALLOWED_HDX_UPDATE_FREQUENCIES", fallback=None)
or Dataset.list_valid_update_frequencies()
)
DUCK_DB_MEMORY_LIMIT = parse_list(
os.environ.get("DUCK_DB_MEMORY_LIMIT")
or config.get("HDX", "DUCK_DB_MEMORY_LIMIT", fallback=None)
)


def get_db_connection_params() -> dict:
Expand Down

0 comments on commit e092c73

Please sign in to comment.