Skip to content

Commit a697fb4

Browse files
achalsadchia
authored andcommitted
chore: Add types hints and set created_timestamp in sql registry (feast-dev#3033)
* chore: Add types for some methods in the sql registry Signed-off-by: Achal Shah <[email protected]> * created_timestamp Signed-off-by: Achal Shah <[email protected]>
1 parent f340aeb commit a697fb4

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

sdk/python/feast/infra/registry_stores/sql.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,16 @@ def _apply_object(
688688
self,
689689
table: Table,
690690
project: str,
691-
id_field_name,
692-
obj,
693-
proto_field_name,
694-
name=None,
691+
id_field_name: str,
692+
obj: Any,
693+
proto_field_name: str,
694+
name: Optional[str] = None,
695695
):
696696
self._maybe_init_project_metadata(project)
697697

698698
name = name or obj.name if hasattr(obj, "name") else None
699699
assert name, f"name needs to be provided for {obj}"
700+
700701
with self.engine.connect() as conn:
701702
update_datetime = datetime.utcnow()
702703
update_time = int(update_datetime.timestamp())
@@ -721,9 +722,16 @@ def _apply_object(
721722
)
722723
conn.execute(update_stmt)
723724
else:
725+
obj_proto = obj.to_proto()
726+
727+
if hasattr(obj_proto, "meta") and hasattr(
728+
obj_proto.meta, "created_timestamp"
729+
):
730+
obj_proto.meta.created_timestamp.FromDatetime(update_datetime)
731+
724732
values = {
725733
id_field_name: name,
726-
proto_field_name: obj.to_proto().SerializeToString(),
734+
proto_field_name: obj_proto.SerializeToString(),
727735
"last_updated_timestamp": update_time,
728736
"project_id": project,
729737
}

sdk/python/tests/unit/test_sql_registry.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ def test_apply_entity_success(sql_registry):
167167
and entity.tags["team"] == "matchmaking"
168168
)
169169

170+
# After the first apply, the created_timestamp should be the same as the last_update_timestamp.
171+
assert entity.created_timestamp == entity.last_updated_timestamp
172+
170173
sql_registry.delete_entity("driver_car_id", project)
171174
assert_project_uuid(project, project_uuid, sql_registry)
172175
entities = sql_registry.list_entities(project)
@@ -255,6 +258,9 @@ def test_apply_feature_view_success(sql_registry):
255258
and feature_view.entities[0] == "fs1_my_entity_1"
256259
)
257260

261+
# After the first apply, the created_timestamp should be the same as the last_update_timestamp.
262+
assert feature_view.created_timestamp == feature_view.last_updated_timestamp
263+
258264
sql_registry.delete_feature_view("my_feature_view_1", project)
259265
feature_views = sql_registry.list_feature_views(project)
260266
assert len(feature_views) == 0

0 commit comments

Comments
 (0)