Skip to content

Commit 6f2e0be

Browse files
committed
[JOIN] Split _as_stateful into helper functions
1 parent da3df51 commit 6f2e0be

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

quixstreams/dataframe/dataframe.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from quixstreams.models.serializers import DeserializerType, SerializerType
5050
from quixstreams.sinks import BaseSink
5151
from quixstreams.state.base import State
52+
from quixstreams.state.base.transaction import PartitionTransaction
5253
from quixstreams.utils.printing import (
5354
DEFAULT_COLUMN_NAME,
5455
DEFAULT_LIVE,
@@ -1852,14 +1853,19 @@ def _as_stateful(
18521853
) -> Callable[[Any, Any, int, Any], T]:
18531854
@functools.wraps(func)
18541855
def wrapper(value: Any, key: Any, timestamp: int, headers: Any) -> Any:
1855-
ctx = message_context()
1856-
transaction = processing_context.checkpoint.get_store_transaction(
1857-
stream_id=stream_id,
1858-
partition=ctx.partition,
1859-
)
18601856
# Pass a State object with an interface limited to the key updates only
18611857
# and prefix all the state keys by the message key
1858+
transaction = _get_transaction(processing_context, stream_id)
18621859
state = transaction.as_state(prefix=key)
18631860
return func(value, key, timestamp, headers, state)
18641861

18651862
return wrapper
1863+
1864+
1865+
def _get_transaction(
1866+
processing_context: ProcessingContext, stream_id: str
1867+
) -> PartitionTransaction:
1868+
return processing_context.checkpoint.get_store_transaction(
1869+
stream_id=stream_id,
1870+
partition=message_context().partition,
1871+
)

0 commit comments

Comments
 (0)