You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d42639b
Browse filesBrowse the repository at this point in the historyBrowse files
=="""WITH "stats" AS (SELECT AVG("a") AS "mean_a", STDDEV("a") AS "stddev_a" FROM (SELECT * FROM "db"."test_model" AS "test_model" WHERE "ds" BETWEEN '1970-01-01' AND '1970-01-01') AS "_0" WHERE TRUE) SELECT "a" AS "a", ("a" - "mean_a") / NULLIF("stddev_a", 0) AS "z_score" FROM (SELECT * FROM "db"."test_model" AS "test_model" WHERE "ds" BETWEEN '1970-01-01' AND '1970-01-01') AS "_1", "stats" AS "stats" WHERE ABS(("a" - "mean_a") / NULLIF("stddev_a", 0)) > 3 AND TRUE"""
709
+
)
710
+
711
+
# The condition must filter the rows being checked, not just the rows used to compute the stats
712
+
rendered_query=model.render_audit_query(
713
+
builtin.z_score_audit,
714
+
column=exp.to_column("a"),
715
+
threshold=exp.convert(3),
716
+
condition=parse_one("b > 0"),
717
+
)
718
+
assert (
719
+
rendered_query.sql()
720
+
=="""WITH "stats" AS (SELECT AVG("a") AS "mean_a", STDDEV("a") AS "stddev_a" FROM (SELECT * FROM "db"."test_model" AS "test_model" WHERE "ds" BETWEEN '1970-01-01' AND '1970-01-01') AS "_0" WHERE "b" > 0) SELECT "a" AS "a", ("a" - "mean_a") / NULLIF("stddev_a", 0) AS "z_score" FROM (SELECT * FROM "db"."test_model" AS "test_model" WHERE "ds" BETWEEN '1970-01-01' AND '1970-01-01') AS "_1", "stats" AS "stats" WHERE ABS(("a" - "mean_a") / NULLIF("stddev_a", 0)) > 3 AND "b" > 0"""
721
+
)
722
+
723
+
724
+
deftest_valid_http_method_audit(model: Model):
725
+
rendered_query=model.render_audit_query(
726
+
builtin.valid_http_method_audit,
727
+
column=exp.to_column("a"),
728
+
)
729
+
assert (
730
+
rendered_query.sql()
731
+
=="""SELECT * FROM (SELECT * FROM "db"."test_model" AS "test_model" WHERE "ds" BETWEEN '1970-01-01' AND '1970-01-01') AS "_0" WHERE NOT "a" IN ('GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT') AND TRUE"""
732
+
)
733
+
734
+
rendered_query=model.render_audit_query(
735
+
builtin.valid_http_method_audit,
736
+
column=exp.to_column("a"),
737
+
condition=parse_one("b > 0"),
738
+
)
739
+
assert (
740
+
rendered_query.sql()
741
+
=="""SELECT * FROM (SELECT * FROM "db"."test_model" AS "test_model" WHERE "ds" BETWEEN '1970-01-01' AND '1970-01-01') AS "_0" WHERE NOT "a" IN ('GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT') AND "b" > 0"""
0 commit comments