Skip to content

Commit bdae562

Browse files
authored
feat: Feast/IKV datetime edgecase errors (#4211)
* feat: Feast/IKV datetime edgecase errors Signed-off-by: Pushkar Gupta <[email protected]> * linter Signed-off-by: Pushkar Gupta <[email protected]> * linter Signed-off-by: Pushkar Gupta <[email protected]> --------- Signed-off-by: Pushkar Gupta <[email protected]>
1 parent ff97053 commit bdae562

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • sdk/python/feast/infra/online_stores/contrib/ikv_online_store

‎sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
Tuple,
1212
)
1313

14+
import pytz
15+
from google.protobuf.timestamp_pb2 import Timestamp
1416
from ikvpy.client import IKVReader, IKVWriter
1517
from ikvpy.clientoptions import ClientOptions, ClientOptionsBuilder
1618
from ikvpy.document import IKVDocument, IKVDocumentBuilder
@@ -162,7 +164,9 @@ def _decode_fields_for_primary_key(
162164
dt: Optional[datetime] = None
163165
dt_bytes = next(value_iter)
164166
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)
166170

167171
# decode other features
168172
features = {}
@@ -252,12 +256,17 @@ def _create_document(
252256
"""Converts feast key-value pairs into an IKV document."""
253257

254258
# 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()
256264
builder = (
257265
IKVDocumentBuilder()
258266
.put_string_field(PRIMARY_KEY_FIELD_NAME, entity_id)
259267
.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(),
261270
)
262271
)
263272

0 commit comments

Comments
 (0)