Skip to content

Commit 63d541d

Browse files
authored
chore: Add types hints and set created_timestamp in sql registry (#3033)
* chore: Add types for some methods in the sql registry Signed-off-by: Achal Shah <achals@gmail.com> * created_timestamp Signed-off-by: Achal Shah <achals@gmail.com>
1 parent 1996596 commit 63d541d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

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

+13-5
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

+6
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ def test_apply_entity_success(sql_registry):
168168
and entity.tags["team"] == "matchmaking"
169169
)
170170

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

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

0 commit comments

Comments
 (0)