Skip to content

Commit 008635d

Browse files
authored
fix: rename values parameter to is_in (#703)
Since `values` is a SQL keyword, it is not suitable as an audit parameter. This renames it to `is_in` which is close to the `IN` SQL keyword while not being one. Fixes #702
1 parent 2ab17f8 commit 008635d

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

docs/concepts/audits.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ Notice how `column` and `threshold` parameters have been set at this point. Thes
5858

5959
Note that the same audit can be applied more than once to the same model with different sets of parameters.
6060

61+
### Naming
62+
Note that it is recommended to avoid using SQL keywords when naming audit parameters.
63+
When an audit uses a SQL keyword, it can be necessary to use quotes when using it.
64+
For example, assuming that `my_audit` uses a `values` parameter, invoking it will require quotes:
65+
66+
```sql linenums="1"
67+
MODEL (
68+
name sushi.items,
69+
audits(
70+
my_audit(column=a, "values"=[1,2,3])
71+
)
72+
)
73+
```
74+
6175
## Built-in audits
6276
SQLMesh comes with a suite of built-in generic audits which covers a broad set of common use cases.
6377

@@ -95,7 +109,7 @@ Example:
95109
MODEL (
96110
name sushi.items,
97111
audits (
98-
accepted_values(column=name, values=['Hamachi', 'Unagi', 'Sake'])
112+
accepted_values(column=name, is_in=['Hamachi', 'Unagi', 'Sake'])
99113
)
100114
);
101115
```

examples/sushi/models/items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"ds": "text",
6161
},
6262
audits=[
63-
("accepted_values", {"column": to_column("name"), "values": ITEMS}),
63+
("accepted_values", {"column": to_column("name"), "is_in": ITEMS}),
6464
("not_null", {"columns": [to_column("name"), to_column("price")]}),
6565
("assert_items_price_exceeds_threshold", {"price": 0}),
6666
],

sqlmesh/core/audit/builtin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
query="""
4747
SELECT *
4848
FROM @this_model
49-
WHERE @column NOT IN @values
49+
WHERE @column NOT IN @is_in
5050
""",
5151
)
5252

tests/core/test_audit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_accepted_values_audit(model: Model):
200200
rendered_query = builtin.accepted_values_audit.render_query(
201201
model,
202202
column=exp.to_column("a"),
203-
values=["value_a", "value_b"],
203+
is_in=["value_a", "value_b"],
204204
)
205205
assert (
206206
rendered_query.sql()

0 commit comments

Comments
 (0)