Skip to content

Commit

Permalink
Fix data ID queries constrained by datasets with empty dimensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Mar 31, 2022
1 parent cefad88 commit 198df4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/registry/queries/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ def _build_dataset_constraint_subquery(
storage.select(
*collections,
dataId=SimpleQuery.Select,
id=None,
# If this dataset type has no dimensions, we're in danger of
# generating an invalid subquery that has no columns in the
# SELECT clause. Any easy fix is to just select some arbitrary
# column that goes unused, like the dataset ID.
id=None if storage.datasetType.dimensions else SimpleQuery.Select,
run=None,
ingestDate=None,
timespan=None,
Expand Down
16 changes: 16 additions & 0 deletions python/lsst/daf/butler/registry/tests/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,22 @@ def testEmptyDimensionsQueries(self):
dataIds.findDatasets(schema, collections=[run2, run1], findFirst=True),
[dataset2],
)
# Query for non-empty data IDs with a constraint on an empty-data-ID
# dataset that exists.
dataIds = registry.queryDataIds(["instrument"], datasets="schema", collections=...)
self.checkQueryResults(
dataIds.subset(unique=True),
[DataCoordinate.standardize(instrument="Cam1", universe=registry.dimensions)],
)
# Again query for non-empty data IDs with a constraint on empty-data-ID
# datasets, but when the datasets don't exist. We delete the existing
# dataset and query just that collection rather than creating a new
# empty collection because this is a bit less likely for our build-time
# logic to shortcut-out (via the collection summaries), and such a
# shortcut would make this test a bit more trivial than we'd like.
registry.removeDatasets([dataset2])
dataIds = registry.queryDataIds(["instrument"], datasets="schema", collections=run2)
self.checkQueryResults(dataIds, [])

def testDimensionDataModifications(self):
"""Test that modifying dimension records via:
Expand Down

0 comments on commit 198df4b

Please sign in to comment.