Predicate

final class lsst.daf.butler.queries.tree.Predicate(*, operands: tuple[tuple[typing.Annotated[lsst.daf.butler.queries.tree._predicate.IsNull | lsst.daf.butler.queries.tree._predicate.Comparison | lsst.daf.butler.queries.tree._predicate.InContainer | lsst.daf.butler.queries.tree._predicate.InRange | lsst.daf.butler.queries.tree._predicate.InQuery | lsst.daf.butler.queries.tree._predicate.BooleanWrapper | lsst.daf.butler.queries.tree._predicate.LogicalNot, FieldInfo(annotation=NoneType, required=True, discriminator='predicate_type')], ...], ...])

Bases: QueryTreeBase

A boolean column expression.

Notes

Predicate is the only class representing a boolean column expression that should be used outside of this module (though the objects it nests appear in its serialized form and hence are not fully private). It provides several classmethod factories for constructing those nested types inside a Predicate instance, and PredicateVisitor subclasses should be used to process them.

Attributes Summary

column_type

A string enumeration value representing the type of the column expression.

model_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

Methods Summary

compare(a, operator, b)

Construct a predicate representing a binary comparison between two non-boolean column expressions.

from_bool(value)

Construct a predicate that always evaluates to True or False.

from_bool_expression(value)

Construct a predicate that wraps a boolean ColumnReference, taking on the value of the underlying ColumnReference.

gather_governors(governors)

Add any governor dimensions that need to be fully identified for this column expression to be sound.

gather_required_columns(columns)

Add any columns required to evaluate this predicate to the given column set.

in_container(member, container)

Construct a predicate that tests whether one column expression is a member of a container of other column expressions.

in_query(member, column, query_tree)

Construct a predicate that tests whether a column expression is present in a single-column projection of a query tree.

in_range(member[, start, stop, step])

Construct a predicate that tests whether an integer column expression is part of a strided range.

is_null(operand)

Construct a predicate that tests whether a column expression is NULL.

logical_and(*args)

Construct a predicate representing the logical AND of this predicate and one or more others.

logical_not()

Construct a predicate representing the logical NOT of this predicate.

logical_or(*args)

Construct a predicate representing the logical OR of this predicate and one or more others.

visit(visitor)

Invoke the visitor interface.

Attributes Documentation

column_type

A string enumeration value representing the type of the column expression.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True, 'strict': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'operands': FieldInfo(annotation=tuple[tuple[Annotated[Union[IsNull, Comparison, InContainer, InRange, InQuery, BooleanWrapper, LogicalNot], FieldInfo(annotation=NoneType, required=True, discriminator='predicate_type')], ...], ...], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

Methods Documentation

classmethod compare(a: IntColumnLiteral | StringColumnLiteral | FloatColumnLiteral | HashColumnLiteral | UUIDColumnLiteral | DateTimeColumnLiteral | TimespanColumnLiteral | RegionColumnLiteral | DimensionKeyReference | DimensionFieldReference | DatasetFieldReference | UnaryExpression | BinaryExpression, operator: Literal['==', '!=', '<', '>', '>=', '<=', 'overlaps'], b: IntColumnLiteral | StringColumnLiteral | FloatColumnLiteral | HashColumnLiteral | UUIDColumnLiteral | DateTimeColumnLiteral | TimespanColumnLiteral | RegionColumnLiteral | DimensionKeyReference | DimensionFieldReference | DatasetFieldReference | UnaryExpression | BinaryExpression) Predicate

Construct a predicate representing a binary comparison between two non-boolean column expressions.

Parameters:
aColumnExpression

First column expression in the comparison.

operatorstr

Enumerated string representing the comparison operator to apply. May be and of “==”, “!=”, “<”, “>”, “<=”, “>=”, or “overlaps”.

bColumnExpression

Second column expression in the comparison.

Returns:
predicatePredicate

Predicate representing the comparison.

classmethod from_bool(value: bool) Predicate

Construct a predicate that always evaluates to True or False.

Parameters:
valuebool

Value the predicate should evaluate to.

Returns:
predicatePredicate

Predicate that evaluates to the given boolean value.

classmethod from_bool_expression(value: DimensionKeyReference | DimensionFieldReference | DatasetFieldReference) Predicate

Construct a predicate that wraps a boolean ColumnReference, taking on the value of the underlying ColumnReference.

Parameters:
valueColumnExpression

Boolean-valued expression to convert to Predicate.

Returns:
predicatePredicate

Predicate representing the expression.

gather_governors(governors: set[str]) None

Add any governor dimensions that need to be fully identified for this column expression to be sound.

Parameters:
governorsset [ str ]

Set of governor dimension names to modify in place.

gather_required_columns(columns: ColumnSet) None

Add any columns required to evaluate this predicate to the given column set.

Parameters:
columnsColumnSet

Set of columns to modify in place.

classmethod in_container(member: IntColumnLiteral | StringColumnLiteral | FloatColumnLiteral | HashColumnLiteral | UUIDColumnLiteral | DateTimeColumnLiteral | TimespanColumnLiteral | RegionColumnLiteral | DimensionKeyReference | DimensionFieldReference | DatasetFieldReference | UnaryExpression | BinaryExpression, container: Iterable[IntColumnLiteral | StringColumnLiteral | FloatColumnLiteral | HashColumnLiteral | UUIDColumnLiteral | DateTimeColumnLiteral | TimespanColumnLiteral | RegionColumnLiteral | DimensionKeyReference | DimensionFieldReference | DatasetFieldReference | UnaryExpression | BinaryExpression]) Predicate

Construct a predicate that tests whether one column expression is a member of a container of other column expressions.

Parameters:
memberColumnExpression

Column expression that may be a member of the container.

containerIterable [ ColumnExpression ]

Container of column expressions to test for membership in.

Returns:
predicatePredicate

Predicate representing the membership test.

classmethod in_query(member: ColumnExpression, column: ColumnExpression, query_tree: QueryTree) Predicate

Construct a predicate that tests whether a column expression is present in a single-column projection of a query tree.

Parameters:
memberColumnExpression

Column expression that may be present in the query.

columnColumnExpression

Column to project from the query.

query_treeQueryTree

Query tree to select from.

Returns:
predicatePredicate

Predicate representing the membership test.

classmethod in_range(member: IntColumnLiteral | StringColumnLiteral | FloatColumnLiteral | HashColumnLiteral | UUIDColumnLiteral | DateTimeColumnLiteral | TimespanColumnLiteral | RegionColumnLiteral | DimensionKeyReference | DimensionFieldReference | DatasetFieldReference | UnaryExpression | BinaryExpression, start: int = 0, stop: int | None = None, step: int = 1) Predicate

Construct a predicate that tests whether an integer column expression is part of a strided range.

Parameters:
memberColumnExpression

Column expression that may be a member of the range.

startint, optional

Beginning of the range, inclusive.

stopint or None, optional

End of the range, exclusive.

stepint, optional

Offset between values in the range.

Returns:
predicatePredicate

Predicate representing the membership test.

classmethod is_null(operand: IntColumnLiteral | StringColumnLiteral | FloatColumnLiteral | HashColumnLiteral | UUIDColumnLiteral | DateTimeColumnLiteral | TimespanColumnLiteral | RegionColumnLiteral | DimensionKeyReference | DimensionFieldReference | DatasetFieldReference | UnaryExpression | BinaryExpression) Predicate

Construct a predicate that tests whether a column expression is NULL.

Parameters:
operandColumnExpression

Column expression to test.

Returns:
predicatePredicate

Predicate representing the NULL check.

logical_and(*args: Predicate) Predicate

Construct a predicate representing the logical AND of this predicate and one or more others.

Parameters:
*argsPredicate

Other predicates.

Returns:
predicatePredicate

Predicate representing the logical AND.

logical_not() Predicate

Construct a predicate representing the logical NOT of this predicate.

Returns:
predicatePredicate

Predicate representing the logical NOT.

logical_or(*args: Predicate) Predicate

Construct a predicate representing the logical OR of this predicate and one or more others.

Parameters:
*argsPredicate

Other predicates.

Returns:
predicatePredicate

Predicate representing the logical OR.

visit(visitor: PredicateVisitor[_A, _O, _L]) _A

Invoke the visitor interface.

Parameters:
visitorPredicateVisitor

Visitor to invoke a method on.

Returns:
resultobject

Forwarded result from the visitor.