Skip to content

Commit 34e3c92

Browse files
committed
[DOP-24570] Drop sorted() from LineageService
1 parent 89d8ff8 commit 34e3c92

File tree

16 files changed

+172
-172
lines changed

16 files changed

+172
-172
lines changed

data_rentgen/db/repositories/column_lineage.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2024-2025 MTS PJSC
22
# SPDX-License-Identifier: Apache-2.0
33

4-
from collections.abc import Sequence
4+
from collections.abc import Collection
55
from datetime import datetime
66
from typing import NamedTuple
77
from uuid import UUID
@@ -71,20 +71,20 @@ async def create_bulk(self, items: list[ColumnLineageDTO]):
7171

7272
async def list_by_job_ids(
7373
self,
74-
job_ids: Sequence[int],
74+
job_ids: Collection[int],
7575
since: datetime,
7676
until: datetime | None,
77-
source_dataset_ids: Sequence[int],
78-
target_dataset_ids: Sequence[int],
77+
source_dataset_ids: Collection[int],
78+
target_dataset_ids: Collection[int],
7979
):
8080
if not job_ids:
8181
return []
8282

8383
where = [
8484
ColumnLineage.created_at >= since,
85-
ColumnLineage.job_id == any_(job_ids), # type: ignore[arg-type]
86-
ColumnLineage.source_dataset_id == any_(source_dataset_ids), # type: ignore[arg-type]
87-
ColumnLineage.target_dataset_id == any_(target_dataset_ids), # type: ignore[arg-type]
85+
ColumnLineage.job_id == any_(list(job_ids)), # type: ignore[arg-type]
86+
ColumnLineage.source_dataset_id == any_(list(source_dataset_ids)), # type: ignore[arg-type]
87+
ColumnLineage.target_dataset_id == any_(list(target_dataset_ids)), # type: ignore[arg-type]
8888
]
8989
if until:
9090
where.append(ColumnLineage.created_at <= until)
@@ -93,30 +93,30 @@ async def list_by_job_ids(
9393

9494
async def list_by_run_ids(
9595
self,
96-
run_ids: Sequence[UUID],
96+
run_ids: Collection[UUID],
9797
since: datetime,
9898
until: datetime | None,
99-
source_dataset_ids: Sequence[int],
100-
target_dataset_ids: Sequence[int],
99+
source_dataset_ids: Collection[int],
100+
target_dataset_ids: Collection[int],
101101
):
102102
if not run_ids:
103103
return []
104104

105105
where = [
106106
ColumnLineage.created_at >= since,
107-
ColumnLineage.run_id == any_(run_ids), # type: ignore[arg-type]
108-
ColumnLineage.source_dataset_id == any_(source_dataset_ids), # type: ignore[arg-type]
109-
ColumnLineage.target_dataset_id == any_(target_dataset_ids), # type: ignore[arg-type]
107+
ColumnLineage.run_id == any_(list(run_ids)), # type: ignore[arg-type]
108+
ColumnLineage.source_dataset_id == any_(list(source_dataset_ids)), # type: ignore[arg-type]
109+
ColumnLineage.target_dataset_id == any_(list(target_dataset_ids)), # type: ignore[arg-type]
110110
]
111111
if until:
112112
where.append(ColumnLineage.created_at <= until)
113113
return await self._get_column_lineage_with_column_relations(where)
114114

115115
async def list_by_operation_ids(
116116
self,
117-
operation_ids: Sequence[UUID],
118-
source_dataset_ids: Sequence[int],
119-
target_dataset_ids: Sequence[int],
117+
operation_ids: Collection[UUID],
118+
source_dataset_ids: Collection[int],
119+
target_dataset_ids: Collection[int],
120120
):
121121
if not operation_ids:
122122
return []
@@ -129,13 +129,13 @@ async def list_by_operation_ids(
129129
where = [
130130
ColumnLineage.created_at >= min_created_at,
131131
ColumnLineage.created_at <= max_created_at,
132-
ColumnLineage.operation_id == any_(operation_ids), # type: ignore[arg-type]
133-
ColumnLineage.source_dataset_id == any_(source_dataset_ids), # type: ignore[arg-type]
134-
ColumnLineage.target_dataset_id == any_(target_dataset_ids), # type: ignore[arg-type]
132+
ColumnLineage.operation_id == any_(list(operation_ids)), # type: ignore[arg-type]
133+
ColumnLineage.source_dataset_id == any_(list(source_dataset_ids)), # type: ignore[arg-type]
134+
ColumnLineage.target_dataset_id == any_(list(target_dataset_ids)), # type: ignore[arg-type]
135135
]
136136
return await self._get_column_lineage_with_column_relations(where)
137137

138-
async def _get_column_lineage_with_column_relations(self, where: list[ColumnElement]):
138+
async def _get_column_lineage_with_column_relations(self, where: Collection[ColumnElement]):
139139
query = (
140140
select(
141141
ColumnLineage.source_dataset_id,

data_rentgen/db/repositories/dataset.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-FileCopyrightText: 2024-2025 MTS PJSC
22
# SPDX-License-Identifier: Apache-2.0
3-
from collections.abc import Sequence
3+
from collections.abc import Collection
44

55
from sqlalchemy import (
66
ColumnElement,
@@ -41,12 +41,12 @@ async def paginate(
4141
self,
4242
page: int,
4343
page_size: int,
44-
dataset_ids: Sequence[int],
44+
dataset_ids: Collection[int],
4545
search_query: str | None,
4646
) -> PaginationDTO[Dataset]:
4747
where = []
4848
if dataset_ids:
49-
where.append(Dataset.id == any_(dataset_ids)) # type: ignore[arg-type]
49+
where.append(Dataset.id == any_(list(dataset_ids))) # type: ignore[arg-type]
5050

5151
query: Select | CompoundSelect
5252
order_by: list[ColumnElement | SQLColumnExpression]
@@ -92,18 +92,18 @@ async def paginate(
9292
page_size=page_size,
9393
)
9494

95-
async def list_by_ids(self, dataset_ids: Sequence[int]) -> list[Dataset]:
95+
async def list_by_ids(self, dataset_ids: Collection[int]) -> list[Dataset]:
9696
if not dataset_ids:
9797
return []
9898
query = (
9999
select(Dataset)
100-
.where(Dataset.id == any_(dataset_ids)) # type: ignore[arg-type]
100+
.where(Dataset.id == any_(list(dataset_ids))) # type: ignore[arg-type]
101101
.options(selectinload(Dataset.location).selectinload(Location.addresses))
102102
)
103103
result = await self._session.scalars(query)
104104
return list(result.all())
105105

106-
async def get_stats_by_location_ids(self, location_ids: Sequence[int]) -> dict[int, Row]:
106+
async def get_stats_by_location_ids(self, location_ids: Collection[int]) -> dict[int, Row]:
107107
if not location_ids:
108108
return {}
109109

@@ -113,7 +113,7 @@ async def get_stats_by_location_ids(self, location_ids: Sequence[int]) -> dict[i
113113
func.count(Dataset.id.distinct()).label("total_datasets"),
114114
)
115115
.where(
116-
Dataset.location_id == any_(location_ids), # type: ignore[arg-type]
116+
Dataset.location_id == any_(list(location_ids)), # type: ignore[arg-type]
117117
)
118118
.group_by(Dataset.location_id)
119119
)

data_rentgen/db/repositories/dataset_symlink.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2024-2025 MTS PJSC
22
# SPDX-License-Identifier: Apache-2.0
33

4-
from collections.abc import Sequence
4+
from collections.abc import Collection
55

66
from sqlalchemy import any_, or_, select
77

@@ -23,14 +23,14 @@ async def create_or_update(self, dataset_symlink: DatasetSymlinkDTO) -> DatasetS
2323
return await self._create(dataset_symlink)
2424
return await self._update(result, dataset_symlink)
2525

26-
async def list_by_dataset_ids(self, dataset_ids: Sequence[int]) -> list[DatasetSymlink]:
26+
async def list_by_dataset_ids(self, dataset_ids: Collection[int]) -> list[DatasetSymlink]:
2727
if not dataset_ids:
2828
return []
2929

3030
query = select(DatasetSymlink).where(
3131
or_(
32-
DatasetSymlink.from_dataset_id == any_(dataset_ids), # type: ignore[arg-type]
33-
DatasetSymlink.to_dataset_id == any_(dataset_ids), # type: ignore[arg-type]
32+
DatasetSymlink.from_dataset_id == any_(list(dataset_ids)), # type: ignore[arg-type]
33+
DatasetSymlink.to_dataset_id == any_(list(dataset_ids)), # type: ignore[arg-type]
3434
),
3535
)
3636
scalars = await self._session.scalars(query)

data_rentgen/db/repositories/input.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-FileCopyrightText: 2024-2025 MTS PJSC
22
# SPDX-License-Identifier: Apache-2.0
3-
from collections.abc import Sequence
3+
from collections.abc import Collection
44
from dataclasses import dataclass
55
from datetime import datetime, timezone
66
from typing import Literal
@@ -84,7 +84,7 @@ async def create_or_update_bulk(self, inputs: list[InputDTO]) -> None:
8484

8585
async def list_by_operation_ids(
8686
self,
87-
operation_ids: Sequence[UUID],
87+
operation_ids: Collection[UUID],
8888
granularity: Literal["JOB", "RUN", "OPERATION"],
8989
) -> list[InputRow]:
9090
if not operation_ids:
@@ -98,14 +98,14 @@ async def list_by_operation_ids(
9898
where = [
9999
Input.created_at >= min_created_at,
100100
Input.created_at <= max_created_at,
101-
Input.operation_id == any_(operation_ids), # type: ignore[arg-type]
101+
Input.operation_id == any_(list(operation_ids)), # type: ignore[arg-type]
102102
]
103103

104104
return await self._get_inputs(where, granularity)
105105

106106
async def list_by_run_ids(
107107
self,
108-
run_ids: Sequence[UUID],
108+
run_ids: Collection[UUID],
109109
since: datetime,
110110
until: datetime | None,
111111
granularity: Literal["JOB", "RUN", "OPERATION"],
@@ -118,7 +118,7 @@ async def list_by_run_ids(
118118

119119
where = [
120120
Input.created_at >= min_created_at,
121-
Input.run_id == any_(run_ids), # type: ignore[arg-type]
121+
Input.run_id == any_(list(run_ids)), # type: ignore[arg-type]
122122
]
123123
if until:
124124
where.append(Input.created_at <= until)
@@ -127,7 +127,7 @@ async def list_by_run_ids(
127127

128128
async def list_by_job_ids(
129129
self,
130-
job_ids: Sequence[int],
130+
job_ids: Collection[int],
131131
since: datetime,
132132
until: datetime | None,
133133
granularity: Literal["JOB", "RUN", "OPERATION"],
@@ -137,7 +137,7 @@ async def list_by_job_ids(
137137

138138
where = [
139139
Input.created_at >= since,
140-
Input.job_id == any_(job_ids), # type: ignore[arg-type]
140+
Input.job_id == any_(list(job_ids)), # type: ignore[arg-type]
141141
]
142142
if until:
143143
where.append(Input.created_at <= until)
@@ -146,7 +146,7 @@ async def list_by_job_ids(
146146

147147
async def list_by_dataset_ids(
148148
self,
149-
dataset_ids: Sequence[int],
149+
dataset_ids: Collection[int],
150150
since: datetime,
151151
until: datetime | None,
152152
granularity: Literal["JOB", "RUN", "OPERATION"],
@@ -156,7 +156,7 @@ async def list_by_dataset_ids(
156156

157157
where = [
158158
Input.created_at >= since,
159-
Input.dataset_id == any_(dataset_ids), # type: ignore[arg-type]
159+
Input.dataset_id == any_(list(dataset_ids)), # type: ignore[arg-type]
160160
]
161161
if until:
162162
where.append(Input.created_at <= until)
@@ -165,7 +165,7 @@ async def list_by_dataset_ids(
165165

166166
async def _get_inputs(
167167
self,
168-
where: list[ColumnElement],
168+
where: Collection[ColumnElement],
169169
granularity: Literal["JOB", "RUN", "OPERATION"],
170170
) -> list[InputRow]:
171171
if granularity == "OPERATION":
@@ -277,7 +277,7 @@ async def _get_inputs(
277277
)
278278
return results
279279

280-
async def get_stats_by_operation_ids(self, operation_ids: Sequence[UUID]) -> dict[UUID, Row]:
280+
async def get_stats_by_operation_ids(self, operation_ids: Collection[UUID]) -> dict[UUID, Row]:
281281
if not operation_ids:
282282
return {}
283283

@@ -298,15 +298,15 @@ async def get_stats_by_operation_ids(self, operation_ids: Sequence[UUID]) -> dic
298298
.where(
299299
Input.created_at >= min_created_at,
300300
Input.created_at <= max_created_at,
301-
Input.operation_id == any_(operation_ids), # type: ignore[arg-type]
301+
Input.operation_id == any_(list(operation_ids)), # type: ignore[arg-type]
302302
)
303303
.group_by(Input.operation_id)
304304
)
305305

306306
query_result = await self._session.execute(query)
307307
return {row.operation_id: row for row in query_result.all()}
308308

309-
async def get_stats_by_run_ids(self, run_ids: Sequence[UUID]) -> dict[UUID, Row]:
309+
async def get_stats_by_run_ids(self, run_ids: Collection[UUID]) -> dict[UUID, Row]:
310310
if not run_ids:
311311
return {}
312312

@@ -322,7 +322,7 @@ async def get_stats_by_run_ids(self, run_ids: Sequence[UUID]) -> dict[UUID, Row]
322322
)
323323
.where(
324324
Input.created_at >= min_created_at,
325-
Input.run_id == any_(run_ids), # type: ignore[arg-type]
325+
Input.run_id == any_(list(run_ids)), # type: ignore[arg-type]
326326
)
327327
.group_by(Input.run_id)
328328
)

data_rentgen/db/repositories/job.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-FileCopyrightText: 2024-2025 MTS PJSC
22
# SPDX-License-Identifier: Apache-2.0
3-
from collections.abc import Sequence
3+
from collections.abc import Collection
44

55
from sqlalchemy import (
66
ColumnElement,
@@ -28,12 +28,12 @@ async def paginate(
2828
self,
2929
page: int,
3030
page_size: int,
31-
job_ids: Sequence[int],
31+
job_ids: Collection[int],
3232
search_query: str | None,
3333
) -> PaginationDTO[Job]:
3434
where = []
3535
if job_ids:
36-
where.append(Job.id == any_(job_ids)) # type: ignore[arg-type]
36+
where.append(Job.id == any_(list(job_ids))) # type: ignore[arg-type]
3737

3838
query: Select | CompoundSelect
3939
order_by: list[ColumnElement | SQLColumnExpression]
@@ -91,18 +91,18 @@ async def create_or_update(self, job: JobDTO) -> Job:
9191
return await self._create(job)
9292
return await self._update(result, job)
9393

94-
async def list_by_ids(self, job_ids: Sequence[int]) -> list[Job]:
94+
async def list_by_ids(self, job_ids: Collection[int]) -> list[Job]:
9595
if not job_ids:
9696
return []
9797
query = (
9898
select(Job)
99-
.where(Job.id == any_(job_ids)) # type: ignore[arg-type]
99+
.where(Job.id == any_(list(job_ids))) # type: ignore[arg-type]
100100
.options(selectinload(Job.location).selectinload(Location.addresses))
101101
)
102102
result = await self._session.scalars(query)
103103
return list(result.all())
104104

105-
async def get_stats_by_location_ids(self, location_ids: Sequence[int]) -> dict[int, Row]:
105+
async def get_stats_by_location_ids(self, location_ids: Collection[int]) -> dict[int, Row]:
106106
if not location_ids:
107107
return {}
108108

@@ -112,7 +112,7 @@ async def get_stats_by_location_ids(self, location_ids: Sequence[int]) -> dict[i
112112
func.count(Job.id.distinct()).label("total_jobs"),
113113
)
114114
.where(
115-
Job.location_id == any_(location_ids), # type: ignore[arg-type]
115+
Job.location_id == any_(list(location_ids)), # type: ignore[arg-type]
116116
)
117117
.group_by(Job.location_id)
118118
)

data_rentgen/db/repositories/location.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-FileCopyrightText: 2024-2025 MTS PJSC
22
# SPDX-License-Identifier: Apache-2.0
3-
from collections.abc import Sequence
3+
from collections.abc import Collection
44

55
from sqlalchemy import (
66
ColumnElement,
@@ -42,14 +42,14 @@ async def paginate(
4242
self,
4343
page: int,
4444
page_size: int,
45-
location_ids: Sequence[int],
45+
location_ids: Collection[int],
4646
location_type: str | None,
4747
search_query: str | None,
4848
) -> PaginationDTO[Location]:
4949
where = []
5050

5151
if location_ids:
52-
where.append(Location.id == any_(location_ids)) # type: ignore[arg-type]
52+
where.append(Location.id == any_(list(location_ids))) # type: ignore[arg-type]
5353

5454
if location_type:
5555
where.append(Location.type == location_type)
@@ -108,7 +108,7 @@ async def _get(self, location: LocationDTO) -> Location | None:
108108
.join(Location.addresses)
109109
.where(
110110
Location.type == location.type,
111-
Address.url == any_(sorted(location.addresses)), # type: ignore[arg-type]
111+
Address.url == any_(list(location.addresses)), # type: ignore[arg-type]
112112
)
113113
)
114114
statement = (

0 commit comments

Comments
 (0)