Skip to content

Commit

Permalink
feat: Feast/IKV datetime edgecase errors (#4211)
Browse files Browse the repository at this point in the history
* feat: Feast/IKV datetime edgecase errors

Signed-off-by: Pushkar Gupta <pushkar.moi@gmail.com>

* linter

Signed-off-by: Pushkar Gupta <pushkar.moi@gmail.com>

* linter

Signed-off-by: Pushkar Gupta <pushkar.moi@gmail.com>

---------

Signed-off-by: Pushkar Gupta <pushkar.moi@gmail.com>
  • Loading branch information
pushkarmoi authored May 21, 2024
1 parent ff97053 commit bdae562
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
Tuple,
)

import pytz
from google.protobuf.timestamp_pb2 import Timestamp
from ikvpy.client import IKVReader, IKVWriter
from ikvpy.clientoptions import ClientOptions, ClientOptionsBuilder
from ikvpy.document import IKVDocument, IKVDocumentBuilder
Expand Down Expand Up @@ -162,7 +164,9 @@ def _decode_fields_for_primary_key(
dt: Optional[datetime] = None
dt_bytes = next(value_iter)
if dt_bytes:
dt = datetime.fromisoformat(str(dt_bytes, "utf-8"))
proto_timestamp = Timestamp()
proto_timestamp.ParseFromString(dt_bytes)
dt = datetime.fromtimestamp(proto_timestamp.seconds, tz=pytz.utc)

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

# initialie builder by inserting primary key and row creation timestamp
event_timestamp_str: str = utils.make_tzaware(event_timestamp).isoformat()
event_timestamp_seconds = int(utils.make_tzaware(event_timestamp).timestamp())
event_timestamp_seconds_proto = Timestamp()
event_timestamp_seconds_proto.seconds = event_timestamp_seconds

# event_timestamp_str: str = utils.make_tzaware(event_timestamp).isoformat()
builder = (
IKVDocumentBuilder()
.put_string_field(PRIMARY_KEY_FIELD_NAME, entity_id)
.put_bytes_field(
EVENT_CREATION_TIMESTAMP_FIELD_NAME, event_timestamp_str.encode("utf-8")
EVENT_CREATION_TIMESTAMP_FIELD_NAME,
event_timestamp_seconds_proto.SerializeToString(),
)
)

Expand Down

0 comments on commit bdae562

Please sign in to comment.