Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Feast/IKV datetime edgecase errors #4211

Merged
merged 3 commits into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading