generated from opensafely-core/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support
where()
after sort_by()
in ehrQL
- Loading branch information
Showing
4 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/spec/sort_and_pick/test_sort_by_interleaved_with_where.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from ..tables import e | ||
|
||
title = "Mixing the order of `sort_by` and `where` operations" | ||
|
||
table_data = { | ||
e: """ | ||
| i1 | i2 | ||
--+-----+--- | ||
1 | 101 | 1 | ||
1 | 102 | 2 | ||
1 | 103 | 2 | ||
2 | 203 | 1 | ||
2 | 202 | 2 | ||
2 | 201 | 2 | ||
""", | ||
} | ||
|
||
|
||
def test_sort_by_before_where(spec_test): | ||
spec_test( | ||
table_data, | ||
e.sort_by(e.i1).where(e.i1 > 102).first_for_patient().i1, | ||
{ | ||
1: 103, | ||
2: 201, | ||
}, | ||
) | ||
|
||
|
||
def test_sort_by_interleaved_with_where(spec_test): | ||
spec_test( | ||
table_data, | ||
e.sort_by(e.i1).where(e.i2 > 1).sort_by(e.i2).first_for_patient().i1, | ||
{ | ||
1: 102, | ||
2: 201, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters