-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: support user-defined macros written as SQL #2505
Comments
i believe you can do this already https://sqlmesh.readthedocs.io/en/stable/concepts/macros/sqlmesh_macros/#macro-functions |
closing for now but happy to discuss alternatives |
But those cannot be reused across models. This feature-request is about having something like this:
With the following content MACRO(
name hash_to_string,
arguments (columns),
)
TO_BASE64(
MD5(
@EACH(@columns, c -> c),
"|",
"",
)
) And then in any model, do something like SELECT @HASH_TO_STRING([a,b,c]) AS my_hash I realize now that my original example wasn't great since it referred to writing audits, but the ask is for writing reusable macros using SQL. |
We do currently support reusable SQL macros written with jinja https://sqlmesh.readthedocs.io/en/stable/concepts/macros/jinja_macros/#user-defined-macro-functions |
Which, presumably, is an argument for having an equivalent in SQL directly. As a SQLMesh user that doesn't have to deal with |
Currently, user-defined macros need to be defined as python. An alternative SQL-based syntax would be more consistent with
MODEL
andAUDIT
. That is, having aMACRO
function to define user-defines macros in.sql
files:For supporting named arguments, perhaps a more general
arguments
could work, i.e.: you'd have to define each argument and its default value (and maybe its type for coercion)?:The text was updated successfully, but these errors were encountered: