1616
1717@validate_call ()
1818def duckdb_connection_default () -> DuckdbConnectionMaker :
19+ # Optional caps via env vars; if unset, DuckDB picks defaults from the cgroup / nproc.
20+ memory_limit = os .getenv ("SMOOSENSE_DUCKDB_MEMORY_LIMIT" )
21+ threads = os .getenv ("SMOOSENSE_DUCKDB_THREADS" )
22+
1923 def maker () -> DuckDBPyConnection :
2024 con = duckdb .connect ()
2125
26+ if memory_limit :
27+ con .execute (f"SET memory_limit='{ memory_limit } '" )
28+ if threads :
29+ con .execute (f"SET threads={ threads } " )
2230 # Now install and load the extension
2331 con .execute ("INSTALL httpfs" )
2432 con .execute ("LOAD httpfs" )
@@ -32,7 +40,6 @@ def maker() -> DuckDBPyConnection:
3240@validate_call (config = ConfigDict (arbitrary_types_allowed = True ))
3341def duckdb_connection_using_s3 (
3442 s3_client : BaseClient | None = None ,
35- memory_limit : str = "3GB" ,
3643) -> DuckdbConnectionMaker :
3744 if s3_client is None :
3845 s3_client = boto3 .client ("s3" )
@@ -62,7 +69,6 @@ def maker() -> DuckDBPyConnection:
6269 # Set home_directory and temp_directory before httpfs auto-installs
6370 con .execute (f"SET home_directory='{ home_directory } '" )
6471 con .execute (f"SET temp_directory='{ temp_directory } '" )
65- con .execute (f"SET memory_limit='{ memory_limit } '" )
6672
6773 # Now install and load the extension
6874 con .execute ("INSTALL httpfs" )
0 commit comments