Skip to content

Commit

Permalink
Add QueryBuilder method for DataId-based WHERE expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Jul 1, 2019
1 parent b65e94d commit 6db6cfb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions python/lsst/daf/butler/sql/queryBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,37 @@ def whereParsedExpression(self, expression, op=and_):
_LOG.debug("where from expression: %s", sqlExpression)
self.whereSqlExpression(sqlExpression, op=op)

def whereDataId(self, dataId, op=and_):
"""Add a dimension constraint from a data ID to the query's WHERE
clause.
All data ID values that correspond to dimension values already included
in the query will be used in the constraint; any others will be
ignored.
Parameters
----------
dataId : `DataId` or `dict`
Data ID to require (at least partial) dimension equality with.
op : `sqlalchemy.sql.operator`
Binary operator to use if a WHERE expression already exists.
Returns
-------
links : `set` of `str`
The data ID keys actually used in the constraint.
"""
links = set()
terms = []
for key, value in dataId.items():
selectable = self.findSelectableForLink(key)
if selectable is not None:
links.add(key)
terms.append(selectable.column[key] == value)
if terms:
self.whereSqlExpression(and_(terms), op=op)
return links

def selectDimensionLink(self, link):
"""Add a dimension link column to the SELECT clause of the query.
Expand Down

0 comments on commit 6db6cfb

Please sign in to comment.