lablup / lablup/backend.ai

Split Querier into single-row and batch patterns

Open
#7,282 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
17h 7m
Merged PRs (30d)
358

Description

## Overview

Refactor Querier pattern to separate single-row and batch query operations for consistency with Updater/BatchUpdater pattern.

## Changes

### Current State

- `Querier`: List query with pagination, conditions, orders
- `QuerierResult`: Contains rows, total_count, pagination info
- `execute_querier`: Executes paginated query

### Target State

**Single-row query (Querier)**:

```python
class QuerierSpec(ABC, Generic[TRow]):
@property
def row_class(self) -> type[TRow]: ...

@dataclass
class Querier(Generic[TRow]):
spec: QuerierSpec[TRow]
pk_value: UUID | str | int

@dataclass
class QuerierResult(Generic[TRow]):
row: TRow

async def execute_querier(...) -> QuerierResult[TRow] | None
```

**Batch query (BatchQuerier)**:

```python
@dataclass
class BatchQuerier: # Current Querier
pagination: QueryPagination
conditions: list[QueryCondition] = field(default_factory=list)
orders: list[QueryOrder] = field(default_factory=list)

@dataclass
class BatchQuerierResult(Generic[Row]): # Current QuerierResult
rows: list[Row]
total_count: int
has_next_page: bool
has_previous_page: bool

async def execute_batch_querier(...) -> BatchQuerierResult[Row]
```

## Tasks

- [ ] Create QuerierSpec and Querier for single-row query by PK
- [ ] Create QuerierResult that returns single row
- [ ] Implement execute_querier for single-row query
- [ ] Rename current Querier to BatchQuerier
- [ ] Rename current QuerierResult to BatchQuerierResult
- [ ] Rename execute_querier to execute_batch_querier
- [ ] Update **init**.py exports
- [ ] Add/update tests

JIRA Issue: BA-3351

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.