Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlmesh/core/model/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def render_audit_query(

query_renderer = QueryRenderer(
audit.query,
audit.dialect,
audit.dialect or self.dialect,
audit.macro_definitions,
path=audit._path or Path(),
jinja_macro_registry=audit.jinja_macros,
Expand Down
18 changes: 18 additions & 0 deletions tests/core/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)
from sqlmesh.core.dialect import parse
from sqlmesh.core.model import (
FullKind,
IncrementalByTimeRangeKind,
Model,
SeedModel,
Expand Down Expand Up @@ -880,3 +881,20 @@ def test_model_inline_audits(sushi_context: Context):
assert len(model.audit_definitions) == 3
assert isinstance(model.audit_definitions["assert_valid_name"], ModelAudit)
model.render_audit_query(model.audit_definitions["assert_positive_id"]).sql() == expected_query


def test_audit_query_normalization():
model = create_sql_model(
"db.test_model",
parse_one("SELECT a, b, ds"),
kind=FullKind(),
dialect="snowflake",
)
rendered_audit_query = model.render_audit_query(
builtin.not_null_audit,
columns=[exp.to_column("a")],
)
assert (
rendered_audit_query.sql("snowflake")
== """SELECT * FROM (SELECT * FROM "DB"."TEST_MODEL" AS "TEST_MODEL") AS "_Q_0" WHERE "A" IS NULL AND TRUE"""
)
Loading