Skip to content

Commit fb50755

Browse files
committed
get_last_job interface
1 parent 9bb9800 commit fb50755

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

ads/feature_store/feature_group.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -750,12 +750,8 @@ def get_features_df(self) -> "pd.DataFrame":
750750
"""
751751
records = []
752752
for feature in self.features:
753-
records.append(
754-
{
755-
"name": feature.feature_name,
756-
"type": feature.feature_type
757-
}
758-
)
753+
records.append({"name": feature.feature_name, "type": feature.feature_type})
754+
759755
return pd.DataFrame.from_records(records)
760756

761757
def get_input_features_df(self) -> "pd.DataFrame":
@@ -926,10 +922,18 @@ def get_last_job(self) -> "FeatureGroupJob":
926922
)
927923

928924
if not self.job_id:
929-
raise ValueError(
930-
"Associated jobs cannot be retrieved before calling 'materialise' or 'delete'."
925+
fg_job = FeatureGroupJob.list(
926+
feature_group_id=self.id,
927+
compartment_id=self.compartment_id,
928+
sort_by="timeCreated",
929+
limit="1",
931930
)
932-
931+
if not fg_job:
932+
raise ValueError(
933+
"Associated jobs cannot be retrieved before calling 'materialise' or 'delete'."
934+
)
935+
self.with_job_id(fg_job[0].id)
936+
return fg_job[0]
933937
return FeatureGroupJob.from_id(self.job_id)
934938

935939
def select(self, features: Optional[List[str]] = []) -> Query:

ads/feature_store/mixin/oci_feature_store.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8; -*-
3+
from ads.common.decorator.utils import class_or_instance_method
34

45
# Copyright (c) 2023 Oracle and/or its affiliates.
56
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
@@ -77,3 +78,44 @@ def init_client(
7778
@property
7879
def client(self) -> oci.feature_store.feature_store_client.FeatureStoreClient:
7980
return super().client
81+
82+
@class_or_instance_method
83+
def list_resource(
84+
cls, compartment_id: str = None, limit: int = 0, **kwargs
85+
) -> list:
86+
"""Generic method to list OCI resources
87+
88+
Parameters
89+
----------
90+
compartment_id : str
91+
Compartment ID of the OCI resources. Defaults to None.
92+
If compartment_id is not specified,
93+
the value of NB_SESSION_COMPARTMENT_OCID in environment variable will be used.
94+
limit : int
95+
The maximum number of items to return. Defaults to 0, All items will be returned
96+
**kwargs :
97+
Additional keyword arguments to filter the resource.
98+
The kwargs are passed into OCI API.
99+
100+
Returns
101+
-------
102+
list
103+
A list of OCI resources
104+
105+
Raises
106+
------
107+
NotImplementedError
108+
List method is not supported or implemented.
109+
110+
"""
111+
if limit:
112+
items = cls._find_oci_method("list")(
113+
cls.check_compartment_id(compartment_id), limit=limit, **kwargs
114+
).data.items
115+
else:
116+
items = oci.pagination.list_call_get_all_results(
117+
cls._find_oci_method("list"),
118+
cls.check_compartment_id(compartment_id),
119+
**kwargs,
120+
).data
121+
return [cls.from_oci_model(item) for item in items]

0 commit comments

Comments
 (0)