Skip to content

Commit

Permalink
Add test coverage for query expression NULL syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dhirving committed Aug 10, 2024
1 parent 5fa2c26 commit 70730b3
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions python/lsst/daf/butler/tests/butler_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,8 @@ def test_boolean_columns(self) -> None:
NULL_ID_2 = 903342 # already exists in the YAML file
records = [
{"id": TRUE_ID, "obs_id": "true-1", "can_see_sky": True},
{"id": FALSE_ID_1, "obs_id": "false-1", "can_see_sky": False},
{"id": FALSE_ID_2, "obs_id": "false-2", "can_see_sky": False},
{"id": FALSE_ID_1, "obs_id": "false-1", "can_see_sky": False, "observation_type": "science"},
{"id": FALSE_ID_2, "obs_id": "false-2", "can_see_sky": False, "observation_type": None},
{"id": NULL_ID_1, "obs_id": "null-1", "can_see_sky": None},
]
for record in records:
Expand Down Expand Up @@ -988,18 +988,33 @@ def _run_query(where: str) -> list[int]:
query_func("exposure.can_see_sky OR exposure = 2001"), [TRUE_ID, FALSE_ID_1]
)

# Find nulls and non-nulls. This is run only against the new query
# system. It appears that the `= NULL` syntax never had test coverage
# in the old query system and doesn't appear to work for any column
# types, not just bool. Not worth fixing since we are dropping that
# code soon.
# Find nulls and non-nulls.
#
# This is run only against the new query system. It appears that the
# `= NULL` syntax never had test coverage in the old query system and
# doesn't work for any column types. Not worth fixing since we are
# dropping that code soon.
nulls = [NULL_ID_1, NULL_ID_2]
non_nulls = [TRUE_ID, FALSE_ID_1, FALSE_ID_2]
self.assertCountEqual(_run_query("exposure.can_see_sky = NULL"), nulls)
self.assertCountEqual(_run_query("exposure.can_see_sky != NULL"), non_nulls)
self.assertCountEqual(_run_query("NULL = exposure.can_see_sky"), nulls)
self.assertCountEqual(_run_query("NULL != exposure.can_see_sky"), non_nulls)

# Check null finding for non-boolean columns, too.
self.assertEqual(
_run_query("exposure.observation_type = NULL AND NOT exposure.can_see_sky"), [FALSE_ID_2]
)
self.assertEqual(
_run_query("exposure.observation_type != NULL AND NOT exposure.can_see_sky"), [FALSE_ID_1]
)
self.assertEqual(
_run_query("NULL = exposure.observation_type AND NOT exposure.can_see_sky"), [FALSE_ID_2]
)
self.assertEqual(
_run_query("NULL != exposure.observation_type AND NOT exposure.can_see_sky"), [FALSE_ID_1]
)

# Test boolean columns in ExpressionFactory.
with butler._query() as query:
x = query.expression_factory
Expand Down

0 comments on commit 70730b3

Please sign in to comment.