QueryBuilder¶
-
class
lsst.daf.butler.registry.queries.QueryBuilder(summary: lsst.daf.butler.registry.queries._structs.QuerySummary, backend: lsst.daf.butler.registry.queries._query_backend.QueryBackend, context: Optional[lsst.daf.butler.registry.queries._query_context.QueryContext, None] = None, relation: Optional[lsst.daf.relation._relation.Relation, None] = None)¶ Bases:
objectA builder for potentially complex queries that join tables based on dimension relationships.
Parameters: - summary :
QuerySummary Struct organizing the dimensions involved in the query.
- backend :
QueryBackend Backend object that represents the
Registryimplementation.- context :
QueryContext, optional Object that manages relation engines and database-side state (e.g. temporary tables) for the query. Must have been created by
backend.context(), which is used ifcontextis not provided.- relation :
Relation, optional Initial relation for the query.
Methods Summary
finish(joinMissing)Finish query constructing, returning a new Queryinstance.joinDataset(datasetType, collections, *, …)Add a dataset search or constraint to the query. Methods Documentation
-
finish(joinMissing: bool = True) → lsst.daf.butler.registry.queries._query.Query¶ Finish query constructing, returning a new
Queryinstance.Parameters: - joinMissing :
bool, optional If
True(default), automatically join any missing dimension element tables (according to the categorization of theQuerySummarythe builder was constructed with).Falseshould only be passed if the caller can independently guarantee that all dimension relationships are already captured in non-dimension tables that have been manually included in the query.
Returns: - query :
Query A
Queryobject that can be executed and used to interpret result rows.
- joinMissing :
-
joinDataset(datasetType: lsst.daf.butler.core.datasets.type.DatasetType, collections: Any, *, isResult: bool = True, findFirst: bool = False) → bool¶ Add a dataset search or constraint to the query.
Unlike other
QueryBuilderjoin methods, this must be called directly to search for datasets of a particular type or constrain the query results based on the exists of datasets. However, all dimensions used to identify the dataset type must have already been included inQuerySummary.requestedwhen initializing theQueryBuilder.Parameters: - datasetType :
DatasetType The type of datasets to search for.
- collections :
Any An expression that fully or partially identifies the collections to search for datasets, such as a
str,re.Pattern, or iterable thereof.can be used to return all collections. See Collection expressions for more information.- isResult :
bool, optional If
True(default), include the dataset ID column in the result columns of the query, allowing completeDatasetRefinstances to be produced from the query results for this dataset type. IfFalse, the existence of datasets of this type is used only to constrain the data IDs returned by the query.joinDatasetmay be called withisResult=Trueat most one time on a particularQueryBuilderinstance.- findFirst :
bool, optional If
True(Falseis default), only include the first match for each data ID, searching the given collections in order. Requires that all entries incollectionsbe regular strings, so there is a clear search order. Ignored ifisResultisFalse.
Returns: - anyRecords :
bool If
True, joining the dataset table was successful and the query should proceed. IfFalse, we were able to determine (from the combination ofdatasetTypeandcollections) that there would be no results joined in from this dataset, and hence (due to the inner join that would normally be present), the full query will return no results.
- datasetType :
- summary :