Skip to content

Commit

Permalink
Make global query and say_obs work
Browse files Browse the repository at this point in the history
  • Loading branch information
fred3m committed Jun 27, 2024
1 parent 59da7b3 commit 44fb862
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
37 changes: 36 additions & 1 deletion python/lsst/rubintv/analysis/service/commands/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from lsst.afw.cameraGeom import FOCAL_PLANE

from ..command import BaseCommand
from ..query import EqualityQuery, ParentQuery, Query

if TYPE_CHECKING:
from ..data import DataCenter
Expand Down Expand Up @@ -59,12 +60,46 @@ class LoadColumnsCommand(BaseCommand):
database: str
columns: list[str]
query: dict | None = None
global_query: dict | None = None
day_obs: str | None = None
response_type: str = "table columns"

def build_contents(self, data_center: DataCenter) -> dict:
# Query the database to return the requested columns
database = data_center.schemas[self.database]
data = database.query(self.columns, self.query)

query: Query | None = None
if self.query is not None:
query = Query.from_dict(self.query)
if self.global_query is not None:
global_query = Query.from_dict(self.global_query)
if query is None:
query = global_query
else:
query = ParentQuery(
children=[query, global_query],
operator="AND",
)
if self.day_obs is not None:
table_name = self.columns[0].split(".")[0]
if "exposure" in table_name:
column = "exposure.day_obs"
elif "visit1" in table_name:
column = "visit1.day_obs"
day_obs_query = EqualityQuery(
column= column,

Check failure on line 90 in python/lsst/rubintv/analysis/service/commands/db.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E251

unexpected spaces around keyword / parameter equals
value=int(self.day_obs.replace("-", "")),
operator="eq",
)
if query is None:
query = day_obs_query
else:
query = ParentQuery(
children=[query, day_obs_query],
operator="AND",
)

data = database.query(self.columns, query)

if not data:
# There is no column data to return
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/rubintv/analysis/service/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def get_primary_match_id(self, column_name: str) -> str:
def query(
self,
columns: list[str],
query: dict | None = None,
query: Query | None = None,
) -> dict[str, list]:
"""Query a table and return the results
Expand Down Expand Up @@ -392,7 +392,7 @@ def query(
# generate the query
query_model = sqlalchemy.and_(*[col.isnot(None) for col in table_columns])
if query is not None:
query_result = Query.from_dict(query)(self)
query_result = query(self)
query_model = sqlalchemy.and_(query_model, query_result.result)
table_name = table_names.union(query_result.tables)

Expand Down

0 comments on commit 44fb862

Please sign in to comment.