Skip to content

Commit

Permalink
Drop wildcards from dataset column references.
Browse files Browse the repository at this point in the history
It's just an unnecessary pain right now.  We can add it back in the
string-parsing layer in the future.
  • Loading branch information
TallJimbo committed Dec 27, 2023
1 parent 6e8c228 commit 13c9c4c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 23 deletions.
9 changes: 4 additions & 5 deletions python/lsst/daf/butler/queries/expression_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
__all__ = ("ExpressionFactory", "ExpressionProxy", "ScalarExpressionProxy", "TimespanProxy", "RegionProxy")

from collections.abc import Iterable
from types import EllipsisType
from typing import TYPE_CHECKING, get_args

from lsst.sphgeom import Region
Expand Down Expand Up @@ -294,7 +293,7 @@ class DatasetTypeProxy:
Parameters
----------
dataset_type : `str` or ``...``
dataset_type : `str`
Dataset type name or wildcard. Wildcards are usable only when the
query contains exactly one dataset type or a wildcard.
Expand All @@ -304,11 +303,11 @@ class DatasetTypeProxy:
associated with datasets rather than their dimensions.
"""

def __init__(self, dataset_type: rt.StringOrWildcard):
def __init__(self, dataset_type: str):
self._dataset_type = dataset_type

def __repr__(self) -> str:
return self._dataset_type if self._dataset_type is not ... else "(...)"
return self._dataset_type

# Attributes are actually fixed, but we implement them with __getattr__
# and __dir__ to avoid repeating the list. And someday they might expand
Expand Down Expand Up @@ -351,7 +350,7 @@ def __getattr__(self, name: str) -> DimensionElementProxy:
return DimensionProxy(element)
return DimensionElementProxy(element)

def __getitem__(self, name: str | EllipsisType) -> DatasetTypeProxy:
def __getitem__(self, name: str) -> DatasetTypeProxy:
return DatasetTypeProxy(name)

def not_(self, operand: rt.Predicate) -> rt.Predicate:
Expand Down
12 changes: 1 addition & 11 deletions python/lsst/daf/butler/queries/relation_tree/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@
"RootRelationBase",
"ColumnExpressionBase",
"PredicateBase",
"StringOrWildcard",
"DatasetFieldName",
"InvalidRelationError",
)

from abc import ABC, abstractmethod
from types import EllipsisType
from typing import TYPE_CHECKING, Annotated, Any, Literal, TypeAlias, cast
from typing import TYPE_CHECKING, Any, Literal, TypeAlias, cast

import pydantic

Expand All @@ -52,14 +50,6 @@
from ._relation import Relation, RootRelation


StringOrWildcard = Annotated[
str | EllipsisType,
pydantic.PlainSerializer(lambda x: "..." if x is ... else x, return_type=str),
pydantic.BeforeValidator(lambda x: ... if x == "..." else x),
pydantic.GetPydanticSchema(lambda _s, h: h(str)),
]


DatasetFieldName: TypeAlias = Literal["dataset_id", "ingest_date", "run", "collection", "rank", "timespan"]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

from ...column_spec import ColumnType
from ...dimensions import Dimension, DimensionElement
from ._base import ColumnExpressionBase, DatasetFieldName, InvalidRelationError, StringOrWildcard
from ._base import ColumnExpressionBase, DatasetFieldName, InvalidRelationError


@final
Expand Down Expand Up @@ -121,8 +121,8 @@ class DatasetFieldReference(ColumnExpressionBase):

expression_type: Literal["dataset_field"] = "dataset_field"

dataset_type: StringOrWildcard
"""Name of the dataset type, or ``...`` to match any dataset type."""
dataset_type: str
"""Name of the dataset type to match any dataset type."""

field: DatasetFieldName
"""Name of the field (i.e. column) in the dataset's logical table."""
Expand Down Expand Up @@ -160,10 +160,7 @@ def column_type(self) -> ColumnType:
raise AssertionError(f"Invalid field {self.field!r} for dataset.")

def __str__(self) -> str:
if self.dataset_type is ...:
return self.field
else:
return f"{self.dataset_type}.{self.field}"
return f"{self.dataset_type}.{self.field}"


# Union without Pydantic annotation for the discriminator, for use in nesting
Expand Down

0 comments on commit 13c9c4c

Please sign in to comment.