Crates.io | joinery_macros |
lib.rs | joinery_macros |
version | 0.0.1 |
source | src |
created_at | 2023-11-21 14:19:20.685417 |
updated_at | 2023-11-21 14:19:20.685417 |
description | Macros used internally joinery. |
homepage | |
repository | https://github.com/faradayio/joinery |
max_upload_size | |
id | 1044235 |
size | 26,802 |
joinery
: Transpile (some) of BigQuery's "Standard SQL" dialect to other databasesCurrent status: Preparing for a quiet public release, but not yet there. This is currently a proof of concept that runs the tests in tests/sql/
, but which isn't quite ready for anything else. See ARCHITECTURE.md for an overview of the codebase. This code is less than 2 months old, and it was built quickly, so we still have some refactoring to do.
This is an experimental tool to transpile (some) SQL code written in BigQuery's "Standard SQL" dialect into other dialects. For example, it can transform:
SELECT ARRAY(
SELECT DISTINCT val / 2
FROM UNNEST(arr) AS val
WHERE MOD(val, 2) = 0
) AS arr
FROM array_select_data;
...into the Trino-compatible SQL:
SELECT ARRAY_DISTINCT(
TRANSFORM(
FILTER(arr, val -> MOD(val, 2) = 0),
val -> val / 2
)
) AS arr
FROM array_select_data
It even does type inference, which is needed for certain complex transformations! The transformation process makes some effort to preserve whitespace and comments, so the output SQL is still mostly readable.
This is very much a work in progress, though it has enough features to run a large fraction of our production workload. It supports the following databases to some degree:
If you want to run your production workloads, you will almost certainly need to contribute code. In particular, our API coverage is limited. See tests/sql/
for examples of what we support.
In an ideal world, joinery
would do one of two things:
In the real world, neither BigQuery's Standard SQL nor any of our target dialects have any kind of formal semantics, and there has been way too much empiricism and guesswork involved. But joinery
has been designed to approach the ideal over time.
git clone https://github.com/faradayio/joinery.git
cd joinery
cargo install --path .
joinery --help
joinery parse example_queries.csv
joinery sql-test tests/sql/
For the sql-test
test format, see the test format docs.
This is the default. You don't need to do anything.
You can specify Snowflake using
--database snowflake://<user>@<organization>-<account>[.privatelink]/<warehouse>/<database>
You'll also need to set the SNOWFLAKE_PASSWORD
environment variable.
To run under Trino, you may want to load the plugin, as described in java/trino-plugin/README.md
. If you don't mind some unit test failures on FARM_FINGERPRINT
, you can also just run:
docker run --name trino -d -p 8080:8080 trinodb/trino
Then you need to start a Trino shell:
docker exec -it trino trino
...and paste in the contents of ./sql/trino_compat.sql
. This will provide SQL UDFs that implement a bunch of BigQ
Then you can run joinery
with:
--database "trino://anyone@localhost/memory/default"
See ARCHITECTURE.md for an overview of the codebase.
If you're interested in running analytic SQL queries across multiple databases, you may also be interested in:
sqlglot
. Transform between many different SQL dialects. Much better feature coverage than we have, though it may generate incorrect SQL in tricky cases. If you're planning on adjusting your translated queries by hand, or if you need to support a wide variety of dialects, this is probably a better choice than joinery
.dbt-core
.