airbytehq / airbytehq/PyAirbyte

💡 Proposal: `get_state()` and `set_state()` on the Cache interface

Đang mở
#680 0 bình luận 0 reaction 0 người được giao Được @benjaminwilen nhận Xem trên GitHub
Ngôn ngữ chính
Python
Star
344
Fork
77
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
35

Mô tả

This proposal would give a public API for reading and writing stream state for a `Cache` interface.

Signature might be something like:

```py
class CacheBase:
...

def get_state(
stream_name: str,
) -> StreamState | None:
"""Return a stream state object for the provided stream name.

This is a thin wrapper around the internal `StateProvider` interface.
"""
...

def set_state(
stream_name: str,
stream_state: StreamState | dict,
) -> None:
"""Set a stream state object for the provided stream name.

This is a thin wrapper around the internal `StateWriter` interface.
"""
...

def migrate_state(
streams: list[str] | Literal["*"],
to_cache: CacheBase,
) -> None:
"""Copies all matching stream states to the specified `Cache` object.

This is a thin wrapper around the respective `Cache` objects'
`get_state` and `set_state` methods.
"""
...
```

Other considerations:

1. Since there are as of now many different strongly typed `State` classes (`StateMessage`, `StreamState`, etc.), we'd want to think carefully on which (if any) we feel comfortable to make a part of the public interface.
2. It might actually be cleaner to get/set values as `dict` objects, since that would fully avoid needing to expose a public API for the state object itself. (Tradeoff: `dict` objects may be difficult to parse.)
3. It should be noted that manually modifying a `state` artifact for a stream basically _always_ "voids the warranty", and sources and not guaranteed to have stable `state` artifact interfaces over time.
5. This feature is actually more appropriate for migration of state - such as during renames or moving from one state backend to another, or from one table name/alias to a new one. For this reason, I've included a possible `migrate_state()` method in the above which could streamline a "copy-all"-type operation.
6. Internally, states are often cached in memory by the `StateProvider` class. We'd need to take care to invalidate or refresh the caches after a "set" action.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.