Skip to content

Commit

Permalink
Switch SQLAlchemy import style.
Browse files Browse the repository at this point in the history
I think I swung too far in the direction of 'from X import Y' before;
a lot of these very short symbols really need namespace context.
  • Loading branch information
TallJimbo committed Mar 4, 2020
1 parent 91929ab commit 837bf0d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions python/lsst/daf/butler/registry/queries/_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from dataclasses import dataclass
from typing import Mapping, Optional, Sequence, List, Union

from sqlalchemy.sql import FromClause, select, case, and_, or_, ColumnElement
from sqlalchemy.engine import Connection
import sqlalchemy

from ...core import (
DatasetType,
Expand Down Expand Up @@ -64,8 +63,9 @@ class Like:
"""


def makeCollectionsWhereExpression(column: ColumnElement,
collections: CollectionsExpression) -> Optional[ColumnElement]:
def makeCollectionsWhereExpression(column: sqlalchemy.sql.ColumnElement,
collections: CollectionsExpression
) -> Optional[sqlalchemy.sql.ColumnElement]:
"""Construct a boolean SQL expression corresponding to a Python expression
for the collections to search for one or more datasets.
Expand Down Expand Up @@ -101,7 +101,7 @@ def makeCollectionsWhereExpression(column: ColumnElement,
terms.append(column == equalities[0])
if len(equalities) > 1:
terms.append(column.in_(equalities))
return or_(*terms)
return sqlalchemy.sql.or_(*terms)


class DatasetRegistryStorage:
Expand Down Expand Up @@ -129,8 +129,8 @@ class DatasetRegistryStorage:
allow the initial `QueryBuilder` design and implementation to be more
forward-looking.
"""
def __init__(self, connection: Connection, universe: DimensionUniverse,
tables: Mapping[str, FromClause]):
def __init__(self, connection: sqlalchemy.engine.Connection, universe: DimensionUniverse,
tables: Mapping[str, sqlalchemy.sql.FromClause]):
self._connection = connection
self._universe = universe
self._datasetTypeTable = tables["dataset_type"]
Expand Down Expand Up @@ -175,7 +175,7 @@ def fetchDatasetTypes(self, datasetType: DatasetTypeExpression = ...) -> List[Da
whereTerms.append(self._datasetTypeTable.columns.dataset_type_name.like(datasetType.pattern))
else:
raise TypeError(f"Unexpected dataset type expression '{datasetType}' in query.")
query = select([
query = sqlalchemy.sql.select([
self._datasetTypeTable.columns.dataset_type_name,
self._datasetTypeTable.columns.storage_class,
self._datasetTypeDimensionsTable.columns.dimension_name,
Expand All @@ -200,7 +200,7 @@ def fetchDatasetTypes(self, datasetType: DatasetTypeExpression = ...) -> List[Da
def getDatasetSubquery(self, datasetType: DatasetType, *,
collections: CollectionsExpression,
isResult: bool = True,
addRank: bool = False) -> FromClause:
addRank: bool = False) -> sqlalchemy.sql.FromClause:
"""Return a SQL expression that searches for a dataset of a particular
type in one or more collections.
Expand Down Expand Up @@ -252,7 +252,7 @@ def getDatasetSubquery(self, datasetType: DatasetType, *,
)
ranks[collection] = n
columns.append(
case(
sqlalchemy.sql.case(
ranks,
value=self._datasetCollectionTable.columns.collection
).label("rank")
Expand All @@ -262,10 +262,10 @@ def getDatasetSubquery(self, datasetType: DatasetType, *,
collections)
if collectionsTerm is not None:
whereTerms.append(collectionsTerm)
return select(
return sqlalchemy.sql.select(
columns
).select_from(
self._datasetTable.join(self._datasetCollectionTable)
).where(
and_(*whereTerms)
sqlalchemy.sql.and_(*whereTerms)
).alias(datasetType.name)

0 comments on commit 837bf0d

Please sign in to comment.