QueryBuilder¶
- class lsst.daf.butler.registry.queries.QueryBuilder(summary: QuerySummary, backend: QueryBackend, context: QueryContext | None = None, relation: Relation | None = None)¶
- Bases: - object- A builder for potentially complex queries that join tables based on dimension relationships. - Parameters:
- summaryQuerySummary
- Struct organizing the dimensions involved in the query. 
- backendQueryBackend
- Backend object that represents the - Registryimplementation.
- contextQueryContext, 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 if- contextis not provided.
- relationRelation, optional
- Initial relation for the query. 
 
- summary
 - 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) Query¶
- Finish query constructing, returning a new - Queryinstance.- Parameters:
- joinMissingbool, optional
- If - True(default), automatically join any missing dimension element tables (according to the categorization of the- QuerySummarythe 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.
 
- joinMissing
- Returns:
- queryQuery
- A - Queryobject that can be executed and used to interpret result rows.
 
- query
 
 - joinDataset(datasetType: 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 in- QuerySummary.requestedwhen initializing the- QueryBuilder.- Parameters:
- datasetTypeDatasetType
- The type of datasets to search for. 
- collectionsAny
- 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.
- isResultbool, optional
- If - True(default), include the dataset ID column in the result columns of the query, allowing complete- DatasetRefinstances to be produced from the query results for this dataset type. If- False, the existence of datasets of this type is used only to constrain the data IDs returned by the query.- joinDatasetmay be called with- isResult=Trueat most one time on a particular- QueryBuilderinstance.
- findFirstbool, optional
- If - True(- Falseis default), only include the first match for each data ID, searching the given collections in order. Requires that all entries in- collectionsbe regular strings, so there is a clear search order. Ignored if- isResultis- False.
 
- datasetType
- Returns:
- anyRecordsbool
- If - True, joining the dataset table was successful and the query should proceed. If- False, we were able to determine (from the combination of- datasetTypeand- collections) 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.
 
- anyRecords