MBQL <-> SQL translation

TL;DR; Are there APIs available to translate MBQL to and from SQL, and if not, would implementing some scripts that do that be a stupid idea? :slight_smile:

This is related to How does Metabase handle database changes?

We are currently using Metabase to expose some data to some analysts working in different teams throughout the organization, and are wondering how we can provide them with reliable, continuously tested questions and dashboards, and to have a way for developers to update those questions/dashboards programmatically.

Ideally those questions would be MBQL questions to allow the full range of features provided by metabase (I recall that native SQL questions donโ€™t have all of the features that metabase questions have).

Our developers however write in SQL, and we use pgTap to test our database queries.

A while ago were toying with the idea of writing a library that could translate MBQL to and from SQL, so that we can store our questions in tested, version-controlled SQL files, and use the Metabase API to recreate them during our continuous deployment process.
I thought it was a cool idea and itโ€™d like to work more on it, but I was wondering if there were some pitfalls and/or existing features that I am unaware of (granted that this exploration was done last year, so I am not up to date).

Hi @mfoucault

Metabase currently only support MBQL -> Native query (SQL, Mongo, etc).
https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#post-apidatasetnative

It would require being able to parse Native query to convert it to MBQL, which is a massive project if you are only trying to support 1 database, and Metabase currently supports ~15 different databases (plus all the third-party drivers).

But it would also allow multiple other functionality, if parsing was possible, like:
https://github.com/metabase/metabase/issues/10525

Sounds like Serialization might be of interest:
https://www.metabase.com/docs/latest/enterprise-guide/serialization.html
And also this issue:
https://github.com/metabase/metabase/issues/9389