Skip to content

Commit 23e1fb4

Browse files
authored
[FSTORE-433] Add support for event_time as single item list for compatibility purpose (#860)
* Add support for event_time as single item list for compatibility purpose * Add deprecation warning
1 parent 899b190 commit 23e1fb4

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

python/hsfs/feature_group.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,27 @@ def event_time(self):
647647
return self._event_time
648648

649649
@event_time.setter
650-
def event_time(self, feature_name):
651-
self._event_time = feature_name
650+
def event_time(self, feature_name: Optional[str]):
651+
if feature_name is None:
652+
self._event_time = None
653+
return
654+
elif isinstance(feature_name, str):
655+
self._event_time = feature_name
656+
return
657+
elif isinstance(feature_name, list) and len(feature_name) == 1:
658+
if isinstance(feature_name[0], str):
659+
warnings.warn(
660+
"Providing event_time as a single-element list is deprecated"
661+
+ " and will be dropped in future versions. Provide the feature_name string instead.",
662+
DeprecationWarning,
663+
stacklevel=2,
664+
)
665+
self._event_time = feature_name[0]
666+
return
667+
668+
raise ValueError(
669+
"event_time must be a string corresponding to an existing feature name of the Feature Group."
670+
)
652671

653672
@property
654673
def location(self):
@@ -742,7 +761,7 @@ def __init__(
742761

743762
self._avro_schema = None
744763
self._online_topic_name = online_topic_name
745-
self._event_time = event_time
764+
self.event_time = event_time
746765
self._stream = stream
747766
self._deltastreamer_jobconf = None
748767

python/tests/test_feature_group.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616

1717

1818
from hsfs import (
19+
feature_store,
1920
feature_group,
2021
user,
2122
statistics_config,
2223
feature,
2324
storage_connector,
2425
expectation_suite,
26+
util,
2527
)
28+
from hsfs.client.exceptions import FeatureStoreException
29+
import pytest
30+
import warnings
2631

2732

2833
class TestFeatureGroup:
@@ -220,6 +225,35 @@ def test_from_response_json_stream_basic_info(self, backend_fixtures):
220225
assert fg.stream is True
221226
assert fg.expectation_suite is None
222227

228+
def test_constructor_with_list_event_time_for_compatibility(
229+
self, mocker, backend_fixtures, dataframe_fixture_basic
230+
):
231+
# Arrange
232+
mocker.patch("hsfs.client.get_instance")
233+
mocker.patch("hsfs.engine.get_type")
234+
json = backend_fixtures["feature_store"]["get"]["response"]
235+
236+
# Act
237+
fs = feature_store.FeatureStore.from_response_json(json)
238+
with warnings.catch_warnings(record=True) as warning_record:
239+
new_fg = fs.create_feature_group(
240+
name="fg_name",
241+
version=1,
242+
description="fg_description",
243+
event_time=["event_date"],
244+
)
245+
with pytest.raises(FeatureStoreException):
246+
util.verify_attribute_key_names(new_fg, False)
247+
248+
# Assert
249+
assert new_fg.event_time == "event_date"
250+
assert len(warning_record) == 1
251+
assert issubclass(warning_record[0].category, DeprecationWarning)
252+
assert str(warning_record[0].message) == (
253+
"Providing event_time as a single-element list is deprecated"
254+
+ " and will be dropped in future versions. Provide the feature_name string instead."
255+
)
256+
223257

224258
class TestExternalFeatureGroup:
225259
def test_from_response_json(self, backend_fixtures):

0 commit comments

Comments
 (0)