2
2
from collections .abc import Iterator , Sequence , Awaitable
3
3
from dataclasses import dataclass
4
4
from datetime import datetime
5
- from typing import TypeVar , Callable , Union
5
+ from typing import TypeVar , Callable , Union , Optional
6
6
from warnings import warn
7
7
8
8
from pynumaflow ._constants import DROP
@@ -106,33 +106,39 @@ class Datum:
106
106
value: the payload of the event.
107
107
event_time: the event time of the event.
108
108
watermark: the watermark of the event.
109
+ headers: the headers of the event.
110
+
109
111
>>> # Example usage
110
112
>>> from pynumaflow.mapper import Datum
111
113
>>> from datetime import datetime, timezone
112
114
>>> payload = bytes("test_mock_message", encoding="utf-8")
113
115
>>> t1 = datetime.fromtimestamp(1662998400, timezone.utc)
114
116
>>> t2 = datetime.fromtimestamp(1662998460, timezone.utc)
117
+ >>> msg_headers = {"key1": "value1", "key2": "value2"}
115
118
>>> d = Datum(
116
119
... keys=["test_key"],
117
120
... value=payload,
118
121
... event_time=t1,
119
122
... watermark=t2,
123
+ ... headers=msg_headers,
120
124
... )
121
125
"""
122
126
123
- __slots__ = ("_keys" , "_value" , "_event_time" , "_watermark" )
127
+ __slots__ = ("_keys" , "_value" , "_event_time" , "_watermark" , "_headers" )
124
128
125
129
_keys : list [str ]
126
130
_value : bytes
127
131
_event_time : datetime
128
132
_watermark : datetime
133
+ _headers : dict [str , str ]
129
134
130
135
def __init__ (
131
136
self ,
132
137
keys : list [str ],
133
138
value : bytes ,
134
139
event_time : datetime ,
135
140
watermark : datetime ,
141
+ headers : Optional [dict [str , str ]] = None ,
136
142
):
137
143
self ._keys = keys or list ()
138
144
self ._value = value or b""
@@ -142,7 +148,9 @@ def __init__(
142
148
if not isinstance (watermark , datetime ):
143
149
raise TypeError (f"Wrong data type: { type (watermark )} for Datum.watermark" )
144
150
self ._watermark = watermark
151
+ self ._headers = headers or {}
145
152
153
+ @property
146
154
def keys (self ) -> list [str ]:
147
155
"""Returns the keys of the event"""
148
156
return self ._keys
@@ -162,6 +170,11 @@ def watermark(self) -> datetime:
162
170
"""Returns the watermark of the event."""
163
171
return self ._watermark
164
172
173
+ @property
174
+ def headers (self ) -> dict [str , str ]:
175
+ """Returns the headers of the event."""
176
+ return self ._headers .copy ()
177
+
165
178
166
179
class Mapper (metaclass = ABCMeta ):
167
180
"""
0 commit comments