|
11 | 11 | Tuple, |
12 | 12 | ) |
13 | 13 |
|
| 14 | +import pytz |
| 15 | +from google.protobuf.timestamp_pb2 import Timestamp |
14 | 16 | from ikvpy.client import IKVReader, IKVWriter |
15 | 17 | from ikvpy.clientoptions import ClientOptions, ClientOptionsBuilder |
16 | 18 | from ikvpy.document import IKVDocument, IKVDocumentBuilder |
@@ -162,7 +164,9 @@ def _decode_fields_for_primary_key( |
162 | 164 | dt: Optional[datetime] = None |
163 | 165 | dt_bytes = next(value_iter) |
164 | 166 | if dt_bytes: |
165 | | - dt = datetime.fromisoformat(str(dt_bytes, "utf-8")) |
| 167 | + proto_timestamp = Timestamp() |
| 168 | + proto_timestamp.ParseFromString(dt_bytes) |
| 169 | + dt = datetime.fromtimestamp(proto_timestamp.seconds, tz=pytz.utc) |
166 | 170 |
|
167 | 171 | # decode other features |
168 | 172 | features = {} |
@@ -252,12 +256,17 @@ def _create_document( |
252 | 256 | """Converts feast key-value pairs into an IKV document.""" |
253 | 257 |
|
254 | 258 | # initialie builder by inserting primary key and row creation timestamp |
255 | | - event_timestamp_str: str = utils.make_tzaware(event_timestamp).isoformat() |
| 259 | + event_timestamp_seconds = int(utils.make_tzaware(event_timestamp).timestamp()) |
| 260 | + event_timestamp_seconds_proto = Timestamp() |
| 261 | + event_timestamp_seconds_proto.seconds = event_timestamp_seconds |
| 262 | + |
| 263 | + # event_timestamp_str: str = utils.make_tzaware(event_timestamp).isoformat() |
256 | 264 | builder = ( |
257 | 265 | IKVDocumentBuilder() |
258 | 266 | .put_string_field(PRIMARY_KEY_FIELD_NAME, entity_id) |
259 | 267 | .put_bytes_field( |
260 | | - EVENT_CREATION_TIMESTAMP_FIELD_NAME, event_timestamp_str.encode("utf-8") |
| 268 | + EVENT_CREATION_TIMESTAMP_FIELD_NAME, |
| 269 | + event_timestamp_seconds_proto.SerializeToString(), |
261 | 270 | ) |
262 | 271 | ) |
263 | 272 |
|
|
0 commit comments