Skip to content

Commit

Permalink
feat: trino-adapter initial implementation (#1)
Browse files Browse the repository at this point in the history
* feat: trino adapter WIP

* feat: trino adapter completed

* fix: update poetry lock file
  • Loading branch information
TylerHillery authored Dec 26, 2023
1 parent 8eb1c9f commit ae548ef
Show file tree
Hide file tree
Showing 25 changed files with 1,565 additions and 306 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and Publish Package

on:
pull_request:
branches:
- main
types:
- closed

jobs:
publish-package:
if: ${{ github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/v') }}
runs-on: ubuntu-latest

steps:
- name: Check out harlequin-trino main branch
uses: actions/checkout@v4
with:
ref: main
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.6.1
- name: Configure poetry
run: poetry config --no-interaction pypi-token.pypi ${{ secrets.HARLEQUIN_TRINO_PYPI_TOKEN }}
- name: Get harlequin-trino Version
id: harlequin_trino_version
run: echo "harlequin_trino_version=$(poetry version --short)" >> $GITHUB_OUTPUT
- name: Build package
run: poetry build --no-interaction
- name: Publish package to PyPI
run: poetry publish --no-interaction
- name: Create a Github Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.harlequin_trino_version.outputs.harlequin_trino_version }}
target_commitish: main
token: ${{ secrets.HARLEQUIN_TRINO_RELEASE_TOKEN }}
body_path: CHANGELOG.md
files: |
LICENSE
dist/*harlequin*.whl
dist/*harlequin*.tar.gz
57 changes: 57 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Create Release Branch

on:
workflow_dispatch:
inputs:
newVersion:
description: A version number for this release (e.g., "0.1.0")
required: true

jobs:
prepare-release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Check out harlequin-trino main branch
uses: actions/checkout@v4
with:
ref: main
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.6.1
- name: Create release branch
run: |
git checkout -b release/v${{ github.event.inputs.newVersion }}
git push --set-upstream origin release/v${{ github.event.inputs.newVersion }}
- name: Bump version
run: poetry version ${{ github.event.inputs.newVersion }} --no-interaction
- name: Ensure package can be built
run: poetry build --no-interaction
- name: Update CHANGELOG
uses: thomaseizinger/keep-a-changelog-new-release@v1
with:
version: ${{ github.event.inputs.newVersion }}
- name: Commit Changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Bumps version to ${{ github.event.inputs.newVersion }}
- name: Create pull request into main
uses: thomaseizinger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
head: release/v${{ github.event.inputs.newVersion }}
base: main
title: v${{ github.event.inputs.newVersion }}
body: >
This PR was automatically generated. It bumps the version number
in pyproject.toml and updates CHANGELOG.md. You may have to close
this PR and reopen it to get the required checks to run.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Harlequin-Trino CHANGELOG

All notable changes to this project will be documented in this file.

## [Unreleased]

### Features
- Adds a basic Trino adapter with most common connection options.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Ted Conbeer
Copyright (c) 2023 Tyler Hillery

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: check
check:
ruff format .
ruff . --fix
mypy
pytest

.PHONY: init
init:
docker-compose up -d

.PHONY: clean
clean:
docker-compose down

.PHONY: serve
serve:
harlequin -P None -a trino --host localhost -p 8080 -U trino
74 changes: 71 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,72 @@
# harlequin-adapter-template
This repo provides a template you can use to accelerate development of a new [Harlequin](https://harlequin.sh) database adapter.
# harlequin-trino

For an in-depth guide on writing your own adapter, see the [Harlequin Docs](https://harlequin.sh/docs/contributing/adapter-guide).
This repo provides the Harlequin adapter for Trino.

## Installation

`harlequin-trino` depends on `harlequin`, so installing this package will also install Harlequin.

### Using pip

To install this adapter into an activated virtual environment:
```bash
pip install harlequin-trino
```

### Using poetry

```bash
poetry add harlequin-trino
```

### Using pipx

If you do not already have Harlequin installed:

```bash
pip install harlequin-trino
```

If you would like to add the Trino adapter to an existing Harlequin installation:

```bash
pipx inject harlequin harlequin-trino
```

### As an Extra
Alternatively, you can install Harlequin with the `trino` extra:

```bash
pip install harlequin[trino]
```

```bash
poetry add harlequin[trino]
```

```bash
pipx install harlequin[trino]
```

## Usage and Configuration
For a minimum connection you are going to need:
- host
- port
- user

```bash
harlequin -a trino -h localhost -p 8080 -U my_user
```

If your trino instance requires a password you can set the `--require_auth` flag to password and use the `--password` flag for your password
```bash
harlequin -a trino -h localhost -p 8080 -U my_user --password my-pass --require_auth password
```

Many more options are available; to see the full list, run:

```bash
harlequin --help
```

For more information, see the [Harlequin Docs](https://harlequin.sh/docs/trino/index).
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '3.1'

services:
db:
image: postgres:latest
restart: always
environment:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432

trino:
image: trinodb/trino
restart: always
ports:
- 8080:8080
volumes:
- ./trino/etc:/etc/trino

adminer:
image: adminer
restart: always
ports:
- 8081:8080

networks:
shared_network:
driver: bridge
Loading

0 comments on commit ae548ef

Please sign in to comment.