Skip to content

Commit

Permalink
Add commutator for FindFirstDataset.
Browse files Browse the repository at this point in the history
I don't know why I previously assumed this wouldn't commute with
anything; it commutes in essentially exactly the same way as a
Selection (i.e. WHERE clause).
  • Loading branch information
TallJimbo committed Jul 28, 2023
1 parent f438ab7 commit f1788e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/changes/DM-40184.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a rare bug in follow-up dataset queries involving relation commutators.

This occurred when building QuantumGraphs where a "warp" dataset type was an overall input to the pipeline and present in more than one input RUN collection.
23 changes: 22 additions & 1 deletion python/lsst/daf/butler/registry/queries/find_first_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from collections.abc import Sequence, Set
from typing import final

from lsst.daf.relation import ColumnTag, Relation, RowFilter
from lsst.daf.relation import ColumnTag, Relation, RowFilter, UnaryCommutator, UnaryOperationRelation
from lsst.utils.classes import cached_getter

from ...core import DatasetColumnTag, DimensionKeyColumnTag
Expand Down Expand Up @@ -73,3 +73,24 @@ def __str__(self) -> str:
def applied_min_rows(self, target: Relation) -> int:
# Docstring inherited.
return 1 if target.min_rows else 0

def commute(self, current: UnaryOperationRelation) -> UnaryCommutator:
# Docstring inherited.
if not self.columns_required <= current.target.columns:
return UnaryCommutator(

Check warning on line 80 in python/lsst/daf/butler/registry/queries/find_first_dataset.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/registry/queries/find_first_dataset.py#L80

Added line #L80 was not covered by tests
first=None,
second=current.operation,
done=False,
messages=(
f"{current.target} is missing columns "
f"{set(self.columns_required - current.target.columns)}",
),
)
if current.operation.is_count_dependent:
return UnaryCommutator(

Check warning on line 90 in python/lsst/daf/butler/registry/queries/find_first_dataset.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/registry/queries/find_first_dataset.py#L90

Added line #L90 was not covered by tests
first=None,
second=current.operation,
done=False,
messages=(f"{current.operation} is count-dependent",),
)
return UnaryCommutator(self, current.operation)
1 change: 0 additions & 1 deletion python/lsst/daf/butler/registry/tests/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3428,7 +3428,6 @@ def pop_transfer(tree: Relation) -> Relation:
sql.Engine,
)

@unittest.expectedFailure
def test_query_find_datasets_drop_postprocessing(self) -> None:
"""Test that DataCoordinateQueryResults.findDatasets will strip
postprocessing operations when it needs to.
Expand Down

0 comments on commit f1788e9

Please sign in to comment.