dbt-unit-testing
sqlglot
dbt-unit-testing | sqlglot | |
---|---|---|
7 | 62 | |
440 | 7,947 | |
1.4% | 2.1% | |
3.5 | 9.9 | |
5 months ago | 4 days ago | |
Shell | Python | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
dbt-unit-testing
-
The SQL Unit Testing Landscape: 2023
If you use dbt for transformations Dbt Unit Testing (https://github.com/EqualExperts/dbt-unit-testing) is getting some attention (https://www.thoughtworks.com/radar/languages-and-frameworks?blipid=202304042)
-
Data-eng related highlights from the latest Thoughtworks Tech Radar
dbt-unit-testing
- I'm not getting it...what's the point of DBT?
-
Ask HN: How do you test SQL?
We use this and take an example-based tests approach for any non-trivial tables: https://github.com/EqualExperts/dbt-unit-testing
-
SQL should be your default choice for data engineering pipelines
> How do you test some SQL logic in isolation?
I do this using sql
1. Extracting an 'ephemeral model' to different model file
2. Mock out this model in upstream model in unit tests https://github.com/EqualExperts/dbt-unit-testing
3. Write unit tests for this model.
This is not different than regular software development in a language like java.
I would argue its even better better because unit tests are always in tabular format and pretty easy to understand. Java unit tests on other hand are never read by devs in practice.
-
Unit testing with dbt
I haven't done it yet but there are some popular blogs as well as a DBT package someone created.
-
Modern Data Modeling: Start with the End?
> I really don’t understand the communities obsession with unwieldy tools like DBT.
It lets me write test first sql transforms. I never thought TDD sql would be possible. My sql is so much more readable with common logic extracted into ephmeral models. I practice same method to write clear code to write sql, eg: too many mocks = refactor into separate model ( class) .
I think DBT made this possible with refs that can be swapped out with mocks. This is the awesome library I am using https://github.com/EqualExperts/dbt-unit-testing
sqlglot
-
Show HN: SQL-tString a t-string SQL builder in Python
https://github.com/tobymao/sqlglot :
> SQLGlot is a no-dependency SQL parser, transpiler, optimizer, and engine [written in Python] . It can be used to format SQL or translate between 24 different dialects like DuckDB, Presto / Trino, Spark / Databricks, Snowflake, and BigQuery. It aims to read a wide variety of SQL inputs and output syntactically and semantically correct SQL in the targeted dialects.
-
Ask HN: What are you working on? (April 2025)
Thanks for the suggestion! I am using https://github.com/tobymao/sqlglot, which magically supports most SQL dialects. And yes, support for DuckDB is also in future plans
-
Anatomy of a SQL Engine
I recommend anyone who works with databases to write a simple engine. It's a lot simpler than you may think and it's a great exercise. If using python, sqlglot (https://github.com/tobymao/sqlglot) let's you skip all the parsing and it even does some simple optimizations. From the parsed query tree it's pretty straightforward to build a logical plan and execute that. You can even use python's builtin ast module to convert sql expressions into python ones (so no need for a custom interpreter!)
-
Duckberg!
This could be a nice option to add sqlglot here. As an advanced sql parsing library.
-
Writing Composable SQL Using Knex and Pipelines
You can compose SQL with https://ibis-project.org/tutorials/ibis-for-sql-users, which is using https://github.com/tobymao/sqlglot to parse the SQL under the hood.
As an alternative to parsing the SQL yourself, DuckDB's [relational API](https://duckdb.org/docs/api/python/relational_api) allows you to compose SQL expressions efficiently and lazily, which I've used when playing around with thinks like https://gist.github.com/ajfriend/eea0795546c7c44f1c24ab0560a...
-
SQL Tips and Tricks
SQLFluff is a linter formatter written in Python https://sqlfluff.com/
Heard there is a faster one called sqruff, but I have not tried it
https://www.quary.dev/blog/sqruff-launch
Might also be able to cajole sqlglot into being a formatter but it's designed for forgiving dialect conversion, not formatting
https://github.com/tobymao/sqlglot
-
The Future of MySQL is PostgreSQL: an extension for the MySQL wire protocol
This is probably referring to "zero changes to your driver code" and not "zero changes to the SQL you send over this driver".
Translating between SQL dialects is notoriously hard and attempts to translate [1] are working in 95% of cases. But the last 5% would require 5x amount of work. That's because "SQL dialect" also includes weird edge cases of type inference of things like COALESCE(5, FALSE) and emulation of system catalogs (pg_catalog, information_schema).
[1] https://github.com/tobymao/sqlglot
- FLaNK AI Weekly 18 March 2024
- SQLGlot: No-dependency SQL parser, transpiler, optimizer for 21 SQL dialects
-
Transpile Any SQL to PostgreSQL Dialect
Recommend checking out https://github.com/tobymao/sqlglot if you are interested in this capability for other SQL dialects
Tools like this are helpful for:
- Rendering SQL in a consistent way, eg for snapshot testing
What are some alternatives?
integresql - IntegreSQL manages isolated PostgreSQL databases for your integration tests.
sqloxide - Python bindings for sqlparser-rs
SS-Unit - A 100% T-SQL based unit testing framework for SQL Server
Apache Calcite - Apache Calcite
hash-db - Experimental distributed pseudomultimodel keyvalue database (it uses python dictionaries) imitating dynamodb querying with join only SQL support, distributed joins and simple Cypher graph support and document storage [GET https://api.github.com/repos/samsquire/hash-db: 404 - Not Found // See: https://docs.github.com/rest/repos/repos#get-a-repository]
JSqlParser - JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern