Skip to content
Open
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
24 changes: 8 additions & 16 deletions smoosense-py/smoosense/utils/duckdb_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ def duckdb_connection_default() -> DuckdbConnectionMaker:
def maker() -> DuckDBPyConnection:
con = duckdb.connect()

# DuckDB's default temp_directory is ".tmp" relative to CWD, which fails
# when CWD is read-only (e.g. read-only mounted datasets).
home_directory = os.getenv("HOME", "/tmp")
temp_directory = os.path.join(home_directory, ".tmp")
os.makedirs(temp_directory, exist_ok=True)
con.execute(f"SET home_directory='{home_directory}'")
con.execute(f"SET temp_directory='{temp_directory}'")
if memory_limit:
con.execute(f"SET memory_limit='{memory_limit}'")
if threads:
con.execute(f"SET threads={threads}")
con.execute("SET parquet_metadata_cache=true")
# Now install and load the extension
con.execute("INSTALL httpfs")
con.execute("LOAD httpfs")
Expand Down Expand Up @@ -60,21 +68,7 @@ def maker() -> DuckDBPyConnection:
"or do not pass s3_client if you do not need S3 access."
)
con = duckdb_connection_default()()
home_directory = os.getenv("HOME", "/tmp")
temp_directory = os.path.join(home_directory, ".tmp")

# Ensure temp directory exists
os.makedirs(temp_directory, exist_ok=True)

# Set home_directory and temp_directory before httpfs auto-installs
con.execute(f"SET home_directory='{home_directory}'")
con.execute(f"SET temp_directory='{temp_directory}'")

# Now install and load the extension
con.execute("INSTALL httpfs")
con.execute("LOAD httpfs")
con.execute("INSTALL lance")
con.execute("LOAD lance")
# Configure DuckDB S3 settings
con.execute(f"SET s3_region='{region}'")
con.execute(f"SET s3_access_key_id='{aws_key}'")
Expand All @@ -85,8 +79,6 @@ def maker() -> DuckDBPyConnection:
con.execute(f"SET s3_endpoint='{aws_endpoint}'")
logger.warning(f'Using AWS endpoint "{aws_endpoint}"')

con.execute("SET parquet_metadata_cache=true")

if aws_token:
con.execute(f"SET s3_session_token='{aws_token}'")
return con
Expand Down
Loading