faust.tables.wrappers
¶
Wrappers for windowed tables.
-
class
faust.tables.wrappers.
WindowedKeysView
(mapping: faust.types.tables.WindowWrapperT, event: faust.types.events.EventT = None)[source]¶ The object returned by
windowed_table.keys()
.
-
class
faust.tables.wrappers.
WindowedItemsView
(mapping: faust.types.tables.WindowWrapperT, event: faust.types.events.EventT = None)[source]¶ The object returned by
windowed_table.items()
.-
now
() → Iterator[Tuple[Any, Any]][source]¶ Return all items present in window closest to system time.
-
-
class
faust.tables.wrappers.
WindowedValuesView
(mapping: faust.types.tables.WindowWrapperT, event: faust.types.events.EventT = None)[source]¶ The object returned by
windowed_table.values()
.
-
class
faust.tables.wrappers.
WindowSet
(key: KT, table: faust.types.tables.TableT, wrapper: faust.types.tables.WindowWrapperT, event: faust.types.events.EventT = None) → None[source]¶ Represents the windows available for table key.
Table[k]
returns WindowSet sincek
can exist in multiple windows, and to retrieve an actual item we need a timestamp.The timestamp of the current event (if this is executing in a stream processor), can be used by accessing
.current()
:Table[k].current()
similarly the most recent value can be accessed using
.now()
:Table[k].now()
from delta of the time of the current event:
Table[k].delta(timedelta(hours=3))
or delta from time of other event:
Table[k].delta(timedelta(hours=3), other_event)
-
apply
(op: Callable[[VT, VT], VT], value: VT, event: faust.types.events.EventT = None) → faust.types.tables.WindowSetT[KT, VT][source]¶ Apply operation to all affected windows.
- Return type
WindowSetT
[~KT, ~VT]
-
value
(event: faust.types.events.EventT = None) → VT[source]¶ Return current value.
The selected window depends on the current time-relativity setting used (
relative_to_now()
,relative_to_stream()
,relative_to_field()
, etc.)- Return type
~VT
-
-
class
faust.tables.wrappers.
WindowWrapper
(table: faust.types.tables.TableT, *, relative_to: Union[faust.types.tables._FieldDescriptorT, Callable[Optional[faust.types.events.EventT], Union[float, datetime.datetime]], datetime.datetime, float, None] = None, key_index: bool = False, key_index_table: faust.types.tables.TableT = None) → None[source]¶ Windowed table wrapper.
A windowed table does not return concrete values when keys are accessed, instead
WindowSet
is returned so that the values can be further reduced to the wanted time period.-
key_index
= False¶
-
key_index_table
= None¶
-
clone
(relative_to: Union[faust.types.tables._FieldDescriptorT, Callable[Optional[faust.types.events.EventT], Union[float, datetime.datetime]], datetime.datetime, float, None]) → faust.types.tables.WindowWrapperT[source]¶ Clone this table using a new time-relativity configuration.
- Return type
-
relative_to
(ts: Union[faust.types.tables._FieldDescriptorT, Callable[Optional[faust.types.events.EventT], Union[float, datetime.datetime]], datetime.datetime, float, None]) → faust.types.tables.WindowWrapperT[source]¶ Configure the time-relativity of this windowed table.
- Return type
-
relative_to_now
() → faust.types.tables.WindowWrapperT[source]¶ Configure table to be time-relative to the system clock.
- Return type
-
relative_to_field
(field: faust.types.models.FieldDescriptorT) → faust.types.tables.WindowWrapperT[source]¶ Configure table to be time-relative to a field in the stream.
This means the window will use the timestamp from the event currently being processed in the stream.
Further it will not use the timestamp of the Kafka message, but a field in the value of the event.
For example a model field:
class Account(faust.Record): created: float table = app.Table('foo').hopping( ..., ).relative_to_field(Account.created)
- Return type
-
relative_to_stream
() → faust.types.tables.WindowWrapperT[source]¶ Configure table to be time-relative to the stream.
This means the window will use the timestamp from the event currently being processed in the stream.
- Return type
-
get_timestamp
(event: faust.types.events.EventT = None) → float[source]¶ Get timestamp from event.
- Return type
-
on_recover
(fun: Callable[Awaitable[None]]) → Callable[Awaitable[None]][source]¶ Call after table recovery.
-
on_set_key
(key: Any, value: Any) → None[source]¶ Call when the value for a key in this table is set.
- Return type
None
-
keys
() → KeysView[source]¶ Return table keys view: iterate over keys found in this table.
- Return type
KeysView
[~KT]
-
values
(event: faust.types.events.EventT = None) → ValuesView[source]¶ Return table values view: iterate over values in this table.
- Return type
ValuesView
[+VT_co]
-
items
(event: faust.types.events.EventT = None) → ItemsView[source]¶ Return table items view: iterate over
(key, value)
pairs.- Return type
ItemsView
[~KT, +VT_co]
-