From e06fb3a8be7a66eb1dcf637bc8d214a741cef35b Mon Sep 17 00:00:00 2001 From: Will Scullin Date: Sat, 6 Jul 2024 15:17:07 -0700 Subject: [PATCH] Trino container (#1756) * Add trino container. * Try using container script --------- Co-authored-by: Lloyd Tabb --- .github/workflows/db-trino.yaml | 18 +++++++--- .../malloy-db-trino/src/trino_connection.ts | 2 +- test/trino/trino_start.sh | 34 +++++++++++++++++++ test/trino/trino_stop.sh | 7 ++++ 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100755 test/trino/trino_start.sh create mode 100755 test/trino/trino_stop.sh diff --git a/.github/workflows/db-trino.yaml b/.github/workflows/db-trino.yaml index 6de071722..5869bc64b 100644 --- a/.github/workflows/db-trino.yaml +++ b/.github/workflows/db-trino.yaml @@ -1,6 +1,11 @@ name: Trino DB -on: [pull_request, workflow_call] +on: + pull_request: + workflow_call: + secrets: + BQ_PRESTO_TRINO_KEY: + required: true jobs: # Label of the container job @@ -24,11 +29,14 @@ jobs: npm ci --loglevel error npm run build npm run build-duckdb-db - npm run ping-db trino + ./test/trino/trino_start.sh npm run test packages/malloy-db-trino npm run test test + ./test/trino/trino_stop.sh env: MALLOY_DATABASES: trino - TRINO_SERVER: https://malloytesting-test-cluster.trino.galaxy.starburst.io - TRINO_USER: ${{ secrets.TRINO_USER}} - TRINO_PASSWORD: ${{ secrets.TRINO_PASSWORD}} + BQ_CREDENTIALS_KEY: ${{ secrets.BQ_PRESTO_TRINO_KEY }} + TRINO_CATALOG: bigquery + TRINO_SCHEMA: malloytest + TRINO_SERVER: http://localhost:8090 + TRINO_USER: malloy-ci-bot@malloydata.org diff --git a/packages/malloy-db-trino/src/trino_connection.ts b/packages/malloy-db-trino/src/trino_connection.ts index ad7638e07..e7fa5834c 100644 --- a/packages/malloy-db-trino/src/trino_connection.ts +++ b/packages/malloy-db-trino/src/trino_connection.ts @@ -162,7 +162,7 @@ export class TrinoConnection implements Connection, PersistSQLResults { // TODO: check user is set. this.trino = Trino.create({ server: config.server, - catalog: 'malloy_demo', //config.catalog, + catalog: config.catalog, schema: config.schema, auth: new BasicAuth(config.user!, config.password), }); diff --git a/test/trino/trino_start.sh b/test/trino/trino_start.sh new file mode 100755 index 000000000..95433ba6c --- /dev/null +++ b/test/trino/trino_start.sh @@ -0,0 +1,34 @@ +#! /bin/bash +rm -rf .tmp +mkdir .tmp + +# generate config file +> ./.tmp/bigquery.properties +cat << EOF > ./.tmp/bigquery.properties +connector.name=bigquery +bigquery.project-id=advance-lacing-417917 +bigquery.credentials-key=$BQ_CREDENTIALS_KEY +bigquery.arrow-serialization.enabled=false +EOF + +# run docker +docker run -p 8090:8080 -d -v ./.tmp/bigquery.properties:/etc/trino/catalog/bigquery.properties --name trino-malloy trinodb/trino + +# wait for server to start +counter=0 +while ! docker logs trino-malloy 2>&1 | grep -q "SERVER STARTED" +do + sleep 1 + counter=$((counter+1)) + # if doesn't start after 2 minutes, output logs and kill process + if [ $counter -eq 120 ] + then + docker logs trino-malloy >& ./.tmp/trino-malloy.logs + docker rm -f trino-malloy + echo "Trino did not start successfully, check .tmp/trino-malloy.logs" + exit 1 + break + fi +done + +echo "Trino running on port localhost:8090" \ No newline at end of file diff --git a/test/trino/trino_stop.sh b/test/trino/trino_stop.sh new file mode 100755 index 000000000..1f1970453 --- /dev/null +++ b/test/trino/trino_stop.sh @@ -0,0 +1,7 @@ +#! /bin/bash + +# clear tmp files +rm -rf .tmp + +# stop container +docker rm -f trino-malloy \ No newline at end of file