From 1c070bfe858fbbbcfacbbe81146146cd5e6befe9 Mon Sep 17 00:00:00 2001 From: avouacr Date: Sat, 6 Jan 2024 15:33:43 +0000 Subject: [PATCH] add scripts to configure R & Python duckdb --- scripts/configure-duckdb.R | 3 +++ scripts/configure-duckdb.py | 6 ++++++ scripts/install-duckdb-extensions.R | 11 ++++------- scripts/onyxia-init.sh | 11 +++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 scripts/configure-duckdb.R create mode 100644 scripts/configure-duckdb.py diff --git a/scripts/configure-duckdb.R b/scripts/configure-duckdb.R new file mode 100644 index 00000000..3ab962bc --- /dev/null +++ b/scripts/configure-duckdb.R @@ -0,0 +1,3 @@ +con <- DBI::dbConnect(duckdb::duckdb()) +DBI::dbExecute(con, 'LOAD httpfs') +DBI::dbExecute(con, glue::glue('SET s3_endpoint=\"{Sys.getenv("AWS_S3_ENDPOINT")}\"')) diff --git a/scripts/configure-duckdb.py b/scripts/configure-duckdb.py new file mode 100644 index 00000000..91ca9371 --- /dev/null +++ b/scripts/configure-duckdb.py @@ -0,0 +1,6 @@ +import os + +import duckdb + +duckdb.sql("LOAD httpfs") +duckdb.sql(f"SET s3_endpoint=\"{os.getenv('AWS_S3_ENDPOINT')}\"") diff --git a/scripts/install-duckdb-extensions.R b/scripts/install-duckdb-extensions.R index cc13e9b6..b08882e1 100755 --- a/scripts/install-duckdb-extensions.R +++ b/scripts/install-duckdb-extensions.R @@ -1,8 +1,5 @@ -library(glue) -library(duckdb) +con <- DBI::dbConnect(duckdb::duckdb()) -con <- dbConnect(duckdb()) - -dbExecute(con, glue('SET extension_directory=\"{Sys.getenv("HOME")}\"')) -dbExecute(con, 'INSTALL httpfs') -dbExecute(con, 'INSTALL aws') +DBI::dbExecute(con, glue::glue('SET extension_directory=\"{Sys.getenv("HOME")}\"')) +DBI::dbExecute(con, 'INSTALL httpfs') +DBI::dbExecute(con, 'INSTALL aws') diff --git a/scripts/onyxia-init.sh b/scripts/onyxia-init.sh index 62683022..c6ed2e8d 100644 --- a/scripts/onyxia-init.sh +++ b/scripts/onyxia-init.sh @@ -166,6 +166,7 @@ if [[ "$DARK_MODE" == "true" ]]; then fi fi +# Configure duckdb CLI if [[ -n $AWS_S3_ENDPOINT ]] && command -v duckdb ; then cat < ${HOME}/.duckdbrc -- Duck head prompt @@ -176,6 +177,16 @@ SET s3_endpoint='$AWS_S3_ENDPOINT'; EOF fi +# Configure duckdb Python API +if [[ -n $AWS_S3_ENDPOINT ]] && command -v python ; then + mamba run -n base python opt/configure-dubkdb.py +fi + +# Configure duckdb R API +if [[ -n $AWS_S3_ENDPOINT ]] && command -v R ; then + Rscript opt/configure-duckdb.R +fi + if [[ -e "$HOME/work" ]]; then if [[ $(id -u) = 0 ]]; then echo "cd $HOME/work" >> /etc/profile