From 66a89ba002cbcd37352328d0f7c0d47c171de873 Mon Sep 17 00:00:00 2001 From: Pushkar Gupta Date: Mon, 20 May 2024 17:56:09 -0700 Subject: [PATCH 1/3] feat: Feast/IKV datetime edgecase errors Signed-off-by: Pushkar Gupta --- .../online_stores/contrib/ikv_online_store/ikv.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py b/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py index 90df7f46860..9a709d0eaa5 100644 --- a/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py +++ b/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py @@ -25,6 +25,9 @@ from feast.repo_config import FeastConfigBaseModel, RepoConfig from feast.usage import log_exceptions_and_usage +import pytz +from google.protobuf.timestamp_pb2 import Timestamp + PRIMARY_KEY_FIELD_NAME: str = "_entity_key" EVENT_CREATION_TIMESTAMP_FIELD_NAME: str = "_event_timestamp" CREATION_TIMESTAMP_FIELD_NAME: str = "_created_timestamp" @@ -162,7 +165,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 = {} @@ -252,12 +257,16 @@ 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() ) ) From c9611d9900ec626d18f56fd763f45fa61ac97654 Mon Sep 17 00:00:00 2001 From: Pushkar Gupta Date: Mon, 20 May 2024 21:24:25 -0700 Subject: [PATCH 2/3] linter Signed-off-by: Pushkar Gupta --- .../infra/online_stores/contrib/ikv_online_store/ikv.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py b/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py index 9a709d0eaa5..fcd3dc71138 100644 --- a/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py +++ b/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py @@ -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 @@ -25,9 +27,6 @@ from feast.repo_config import FeastConfigBaseModel, RepoConfig from feast.usage import log_exceptions_and_usage -import pytz -from google.protobuf.timestamp_pb2 import Timestamp - PRIMARY_KEY_FIELD_NAME: str = "_entity_key" EVENT_CREATION_TIMESTAMP_FIELD_NAME: str = "_event_timestamp" CREATION_TIMESTAMP_FIELD_NAME: str = "_created_timestamp" From da3f6430067aeba594aa2fb54b1f261b5fd17e1c Mon Sep 17 00:00:00 2001 From: Pushkar Gupta Date: Mon, 20 May 2024 22:31:44 -0700 Subject: [PATCH 3/3] linter Signed-off-by: Pushkar Gupta --- .../feast/infra/online_stores/contrib/ikv_online_store/ikv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py b/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py index fcd3dc71138..5d62fd701f4 100644 --- a/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py +++ b/sdk/python/feast/infra/online_stores/contrib/ikv_online_store/ikv.py @@ -265,7 +265,8 @@ def _create_document( IKVDocumentBuilder() .put_string_field(PRIMARY_KEY_FIELD_NAME, entity_id) .put_bytes_field( - EVENT_CREATION_TIMESTAMP_FIELD_NAME, event_timestamp_seconds_proto.SerializeToString() + EVENT_CREATION_TIMESTAMP_FIELD_NAME, + event_timestamp_seconds_proto.SerializeToString(), ) )