Skip to main content

No project description provided

Project description

Harmonizer

PyPI version

Harmonizer is a library for translating Dune queries from PostgreSQL and Spark SQL to DuneSQL. It currently powers our in-app migration service.

Screenshot 2023-05-04 at 11 53 01

Harmonizer makes heavy use of SQLGlot, an excellent tool for working with SQL queries. With it, we parse the query into an Abstract Syntax Tree (AST), and can manipulate the AST, and finally generate the SQL for that query, even in a different dialect.

We add a DuneSQL dialect, and use SQLGlot to translate from Spark SQL/PostgreSQL to DuneSQL. In the DuneSQL dialect, we translate string literals '0x...' to 0x..., since we support native hex literals.

Harmonizer also does a mapping of known changes in table names from the legacy Postgres datasets to corresponding table names in DuneSQL. We need help to make this mapping more complete!

Getting started

Install with

pip install dune-harmonizer

Now import the translate_ functions in your code:

from dune.harmonizer import translate_spark, translate_postgres

with function signatures

def translate_spark(query: str) -> str:
    ...

def translate_postgres(query: str, dataset: str) -> str:
    ...

Contributing

Contributions are very welcome!

Please open an issue or PR, and we will get back to you as soon as we can.

If you've found a table that doesn't get mapped to one that exists on Dune SQL, then you can open an issue or just add the table mapping to this line here in a PR.

If there is a function that doesn't get mapped correctly, then you can open an issue or try and add one here using sqlglot and open a PR.

Development

Install with

poetry install

If the Ruff linter complains, running the following and committing the changes should suffice

poetry run ruff . --fix
poetry run black .

Run tests with

poetry run pytest

We test on examples in the test_cases directory. To force an update of the expected outputs, run the update_expected_outputs script like below

poetry run python tests/update_expected_outputs.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dune_harmonizer-0.34.3.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dune_harmonizer-0.34.3-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file dune_harmonizer-0.34.3.tar.gz.

File metadata

  • Download URL: dune_harmonizer-0.34.3.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1041-azure

File hashes

Hashes for dune_harmonizer-0.34.3.tar.gz
Algorithm Hash digest
SHA256 ecaea206b0c00b71a95cbdfc21a10ac1a59734dabfbe31c7de6b9345006ee510
MD5 48f680937c4e64894c5d112eba9b8f60
BLAKE2b-256 e01ae464ed0358b683b2401f87be382e7baa08713dcb88891bb15a9c414b32ac

See more details on using hashes here.

File details

Details for the file dune_harmonizer-0.34.3-py3-none-any.whl.

File metadata

  • Download URL: dune_harmonizer-0.34.3-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1041-azure

File hashes

Hashes for dune_harmonizer-0.34.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9015a11bcdc521561dbe37252867d10c6c78290d3fe58f866f37a7084833a4cd
MD5 0c0d797259db1f99238d7ea70fa08e31
BLAKE2b-256 41859c5b83be25f34774e4e75d39aa7f3c27e9abca54e455702c75a18bfb0372

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page