Skip to content

Commit 5d87f11

Browse files
authored
Chore: document expected column order in unit tests (#2427)
1 parent c8437c8 commit 5d87f11

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

docs/concepts/tests.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,7 @@ The `rows` key is optional in the above format, so the following would also be v
6060
...
6161
```
6262

63-
### Omitting Columns
64-
65-
Defining the complete inputs and outputs for wide tables, i.e. tables with many columns, can become cumbersome. Therefore, if certain columns can be safely ignored they may be omitted from any row and their value will be treated as `NULL` for that row.
66-
67-
Additionally, it's possible to test only a subset of the output columns by setting `partial` to `true` for the rows of interest:
68-
69-
```yaml linenums="1"
70-
...
71-
outputs:
72-
query:
73-
partial: true
74-
rows:
75-
- <column_name>: <column_value>
76-
...
77-
```
78-
79-
This is useful when we can't treat the missing columns as `NULL`, but still want to ignore them. In order to apply this setting to _all_ outputs, simply set it under the `outputs` key:
80-
81-
```yaml linenums="1"
82-
...
83-
outputs:
84-
partial: true
85-
...
86-
```
87-
88-
When `partial` is set for a _specific_ output, its rows need to be defined as a mapping under the `rows` key and only the columns referenced in them will be tested.
63+
Note: the columns in each row of an expected output must appear in the same relative order as they are selected in the corresponding query.
8964

9065
### Example
9166

@@ -155,7 +130,7 @@ test_example_full_model:
155130
- num_orders: 3
156131
```
157132

158-
Since [omitted columns](#omitting-columns) are treated as `NULL`, this test also implicitly asserts that both the input and the output `item_id` columns are `NULL`, which is correct.
133+
Since [omitted columns](#omitting-columns) are treated as `NULL`, this test also implicitly asserts that both the input and the expected output `item_id` columns are `NULL`, which is correct.
159134

160135
### Testing CTEs
161136

@@ -210,6 +185,33 @@ test_example_full_model:
210185
num_orders: 2
211186
```
212187

188+
### Omitting Columns
189+
190+
Defining the complete inputs and expected outputs for wide tables, i.e. tables with many columns, can become cumbersome. Therefore, if certain columns can be safely ignored they may be omitted from any row and their value will be treated as `NULL` for that row.
191+
192+
Additionally, it's possible to test only a subset of the expected output columns by setting `partial` to `true` for the rows of interest:
193+
194+
```yaml linenums="1"
195+
...
196+
outputs:
197+
query:
198+
partial: true
199+
rows:
200+
- <column_name>: <column_value>
201+
...
202+
```
203+
204+
This is useful when we can't treat the missing columns as `NULL`, but still want to ignore them. In order to apply this setting to _all_ expected outputs, simply set it under the `outputs` key:
205+
206+
```yaml linenums="1"
207+
...
208+
outputs:
209+
partial: true
210+
...
211+
```
212+
213+
When `partial` is set for a _specific_ expected output, its rows need to be defined as a mapping under the `rows` key and only the columns referenced in them will be tested.
214+
213215
### Freezing Time
214216

215217
Some models may use SQL expressions that compute datetime values at a given point in time, such as `CURRENT_TIMESTAMP`. Since these expressions are non-deterministic, it's not enough to simply specify an expected output value in order to test them.

0 commit comments

Comments
 (0)