Skip to content

Commit

Permalink
add scripts to configure R & Python duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
avouacr committed Jan 6, 2024
1 parent 7a7fc21 commit 1c070bf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions scripts/configure-duckdb.R
Original file line number Diff line number Diff line change
@@ -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")}\"'))
6 changes: 6 additions & 0 deletions scripts/configure-duckdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os

import duckdb

duckdb.sql("LOAD httpfs")
duckdb.sql(f"SET s3_endpoint=\"{os.getenv('AWS_S3_ENDPOINT')}\"")
11 changes: 4 additions & 7 deletions scripts/install-duckdb-extensions.R
Original file line number Diff line number Diff line change
@@ -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')
11 changes: 11 additions & 0 deletions scripts/onyxia-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ if [[ "$DARK_MODE" == "true" ]]; then
fi
fi
# Configure duckdb CLI
if [[ -n $AWS_S3_ENDPOINT ]] && command -v duckdb ; then
cat <<EOF > ${HOME}/.duckdbrc
-- Duck head prompt
Expand All @@ -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
Expand Down

0 comments on commit 1c070bf

Please sign in to comment.