DataCoordinateQueryResults¶
- class lsst.daf.butler.registry.queries.DataCoordinateQueryResults(query: Query)¶
- Bases: - DataCoordinateIterable- An enhanced implementation of - DataCoordinateIterablethat represents data IDs retrieved from a database query.- Parameters:
- queryQuery
- Query object that backs this class. 
 
- query
 - Notes - The - Queryclass now implements essentially all of this class’s functionality; “QueryResult” classes like this one now exist only to provide interface backwards compatibility and more specific iterator types.- Attributes Summary - Dimensions identified by these data IDs ( - DimensionGraph).- Universe that defines all known compatible dimensions. - Methods Summary - any(*[, execute, exact])- Test whether this query returns any results. - count(*[, exact, discard])- Count the number of rows this query would return. - expanded()- Return a results object for which - hasRecordsreturns- True.- explain_no_results([execute])- Return human-readable messages that may help explain why the query yields no results. - findDatasets(datasetType, collections, *[, ...])- Find datasets using the data IDs identified by this query. - fromScalar(dataId)- Return a - DataCoordinateIterablecontaining the single data ID.- hasFull()- Indicate if all data IDs in this iterable identify all dimensions. - Return whether all data IDs in this iterable contain records. - limit(limit[, offset])- Make the iterator return limited number of records. - Insert this query's results into a temporary table. - order_by(*args)- Make the iterator return ordered results. - subset([graph, unique])- Return a results object containing a subset of the dimensions of this one, and/or a unique near-subset of its rows. - Transform this iterable into a - DataCoordinateSequence.- toSet()- Transform this iterable into a - DataCoordinateSet.- Attributes Documentation - graph¶
 - universe¶
- Universe that defines all known compatible dimensions. - ( - DimensionUniverse).
 - Methods Documentation - any(*, execute: bool = True, exact: bool = True) bool¶
- Test whether this query returns any results. - Parameters:
- executebool, optional
- If - True, execute at least a- LIMIT 1query if it cannot be determined prior to execution that the query would return no rows.
- exactbool, optional
- If - True, run the full query and perform post-query filtering if needed, until at least one result row is found. If- False, the returned result does not account for post-query filtering, and hence may be- Trueeven when all result rows would be filtered out.
 
- execute
- Returns:
 
 - count(*, exact: bool = True, discard: bool = False) int¶
- Count the number of rows this query would return. - Parameters:
- exactbool, optional
- If - True, run the full query and perform post-query filtering if needed to account for that filtering in the count. If- False, the result may be an upper bound.
- discardbool, optional
- If - True, compute the exact count even if it would require running the full query and then throwing away the result rows after counting them. If- False, this is an error, as the user would usually be better off executing the query first to fetch its rows into a new query (or passing- exact=False). Ignored if- exact=False.
 
- exact
- Returns:
- countint
- The number of rows the query would return, or an upper bound if - exact=False.
 
- count
 - Notes - This counts the number of rows returned, not the number of unique rows returned, so even with - exact=Trueit may provide only an upper bound on the number of deduplicated result rows.
 - expanded() DataCoordinateQueryResults¶
- Return a results object for which - hasRecordsreturns- True.- This method may involve actually executing database queries to fetch - DimensionRecordobjects.- Returns:
- resultsDataCoordinateQueryResults
- A results object for which - hasRecordsreturns- True. May be- selfif that is already the case.
 
- results
 - Notes - For very result sets, it may be much more efficient to call - materializebefore calling- expanded, to avoid performing the original query multiple times (as a subquery) in the follow-up queries that fetch dimension records. For example:- with registry.queryDataIds(...).materialize() as tempDataIds: dataIdsWithRecords = tempDataIds.expanded() for dataId in dataIdsWithRecords: ... 
 - explain_no_results(execute: bool = True) Iterable[str]¶
- Return human-readable messages that may help explain why the query yields no results. 
 - findDatasets(datasetType: Any, collections: Any, *, findFirst: bool = True, components: bool | None = None) DatasetQueryResults¶
- Find datasets using the data IDs identified by this query. - Parameters:
- datasetTypeDatasetTypeorstr
- Dataset type or the name of one to search for. Must have dimensions that are a subset of - self.graph.
- collectionsAny
- An expression that fully or partially identifies the collections to search for the dataset, such as a - str,- re.Pattern, or iterable thereof.- ...can be used to return all collections. See Collection expressions for more information.
- findFirstbool, optional
- If - True(default), for each result data ID, only yield one- DatasetRef, from the first collection in which a dataset of that dataset type appears (according to the order of- collectionspassed in). If- True,- collectionsmust not contain regular expressions and may not be- ....
- componentsbool, optional
- If - True, apply all expression patterns to component dataset type names as well. If- False, never apply patterns to components. If- None(default), apply patterns to components only if their parent datasets were not matched by the expression. Fully-specified component datasets (- stror- DatasetTypeinstances) are always included.- Values other than - Falseare deprecated, and only- Falsewill be supported after v26. After v27 this argument will be removed entirely.
 
- datasetType
- Returns:
- datasetsParentDatasetQueryResults
- A lazy-evaluation object representing dataset query results, iterable over - DatasetRefobjects. If- self.hasRecords(), all nested data IDs in those dataset references will have records as well.
 
- datasets
- Raises:
- ValueError
- Raised if - datasetType.dimensions.issubset(self.graph) is False.
- MissingDatasetTypeError
- Raised if the given dataset type is not registered. 
 
 
 - static fromScalar(dataId: DataCoordinate) _ScalarDataCoordinateIterable¶
- Return a - DataCoordinateIterablecontaining the single data ID.- Parameters:
- dataIdDataCoordinate
- Data ID to adapt. Must be a true - DataCoordinateinstance, not an arbitrary mapping. No runtime checking is performed.
 
- dataId
- Returns:
- iterableDataCoordinateIterable
- A - DataCoordinateIterableinstance of unspecified (i.e. implementation-detail) subclass. Guaranteed to implement the- collections.abc.Sized(i.e.- __len__) and- collections.abc.Container(i.e.- __contains__) interfaces as well as that of- DataCoordinateIterable.
 
- iterable
 
 - hasFull() bool¶
- Indicate if all data IDs in this iterable identify all dimensions. - Not just required dimensions. 
 - limit(limit: int, offset: int | None = 0) DataCoordinateQueryResults¶
- Make the iterator return limited number of records. - Parameters:
- Returns:
- resultDataCoordinateQueryResults
- Returns - selfinstance which is updated to return limited set of records.
 
- result
 - Notes - This method modifies the iterator in place and returns the same instance to support method chaining. Normally this method is used together with - order_bymethod.
 - materialize() Iterator[DataCoordinateQueryResults]¶
- Insert this query’s results into a temporary table. - Returns:
- contexttyping.ContextManager[DataCoordinateQueryResults]
- A context manager that ensures the temporary table is created and populated in - __enter__(returning a results object backed by that table), and dropped in- __exit__. If- selfis already materialized, the context manager may do nothing (reflecting the fact that an outer context manager should already take care of everything else).
 
- context
 - Notes - When using a very large result set to perform multiple queries (e.g. multiple calls to - subsetwith different arguments, or even a single call to- expanded), it may be much more efficient to start by materializing the query and only then performing the follow up queries. It may also be less efficient, depending on how well database engine’s query optimizer can simplify those particular follow-up queries and how efficiently it caches query results even when the are not explicitly inserted into a temporary table. See- expandedand- subsetfor examples.
 - order_by(*args: str) DataCoordinateQueryResults¶
- Make the iterator return ordered results. - Parameters:
- *argsstr
- Names of the columns/dimensions to use for ordering. Column name can be prefixed with minus ( - -) to use descending ordering.
 
- *args
- Returns:
- resultDataCoordinateQueryResults
- Returns - selfinstance which is updated to return ordered result.
 
- result
 - Notes - This method modifies the iterator in place and returns the same instance to support method chaining. 
 - subset(graph: DimensionGraph | None = None, *, unique: bool = False) DataCoordinateQueryResults¶
- Return a results object containing a subset of the dimensions of this one, and/or a unique near-subset of its rows. - This method may involve actually executing database queries to fetch - DimensionRecordobjects.- Parameters:
- graphDimensionGraph, optional
- Dimensions to include in the new results object. If - None,- self.graphis used.
- uniquebool, optional
- If - True(- Falseis default), the query should only return unique data IDs. This is implemented in the database; to obtain unique results via Python-side processing (which may be more efficient in some cases), use- toSetto construct a- DataCoordinateSetfrom this results object instead.
 
- graph
- Returns:
- resultsDataCoordinateQueryResults
- A results object corresponding to the given criteria. May be - selfif it already qualifies.
 
- results
- Raises:
- ValueError
- Raised when - graphis not a subset of the dimension graph in this result.
 
 - Notes - This method can only return a “near-subset” of the original result rows in general because of subtleties in how spatial overlaps are implemented; see - Query.projectedfor more information.- When calling - subsetmultiple times on the same very large result set, it may be much more efficient to call- materializefirst. For example:- dimensions1 = DimensionGraph(...) dimensions2 = DimensionGraph(...) with registry.queryDataIds(...).materialize() as tempDataIds: for dataId1 in tempDataIds.subset( graph=dimensions1, unique=True): ... for dataId2 in tempDataIds.subset( graph=dimensions2, unique=True): ... 
 - toSequence() DataCoordinateSequence¶
- Transform this iterable into a - DataCoordinateSequence.- Returns:
- seqDataCoordinateSequence
- A new - DatasetCoordinateSequencewith the same elements as- self, in the same order. May be- selfif it is already a- DataCoordinateSequence.
 
- seq
 
 - toSet() DataCoordinateSet¶
- Transform this iterable into a - DataCoordinateSet.- Returns:
- setDataCoordinateSet
- A - DatasetCoordinateSetinstance with the same elements as- self, after removing any duplicates. May be- selfif it is already a- DataCoordinateSet.
 
- set