Skip to content
This repository was archived by the owner on Apr 15, 2022. It is now read-only.

Commit 9f20768

Browse files
author
Ben Epstein
authored
Merge pull request #124 from splicemachine/DBAAS-5131
working delete
2 parents 0d35fa0 + 1cbfb84 commit 9f20768

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

splicemachine/features/feature_store.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def get_feature_sets(self, feature_set_names: List[str] = None) -> List[FeatureS
4949
:return: List[FeatureSet] the list of Feature Sets
5050
"""
5151

52-
r = make_request(self._FS_URL, Endpoints.FEATURE_SETS, RequestType.GET, self._basic_auth, { "name": feature_set_names } if feature_set_names else None)
52+
r = make_request(self._FS_URL, Endpoints.FEATURE_SETS, RequestType.GET, self._basic_auth,
53+
{ "name": feature_set_names } if feature_set_names else None)
5354
return [FeatureSet(**fs) for fs in r]
5455

5556
def remove_training_view(self, override=False):
@@ -127,10 +128,6 @@ def get_features_by_name(self, names: Optional[List[str]] = None, as_list=False)
127128
r = make_request(self._FS_URL, Endpoints.FEATURES, RequestType.GET, self._basic_auth, { "name": names })
128129
return [Feature(**f) for f in r] if as_list else pd.DataFrame.from_dict(r)
129130

130-
def remove_feature_set(self):
131-
# TODO
132-
raise NotImplementedError
133-
134131
def get_feature_vector(self, features: List[Union[str, Feature]],
135132
join_key_values: Dict[str, str], return_sql=False) -> Union[str, PandasDF]:
136133
"""
@@ -184,7 +181,8 @@ def get_training_view_features(self, training_view: str) -> List[Feature]:
184181
:return: A list of available Feature objects
185182
"""
186183

187-
r = make_request(self._FS_URL, Endpoints.TRAINING_VIEW_FEATURES, RequestType.GET, self._basic_auth, { "view": training_view })
184+
r = make_request(self._FS_URL, Endpoints.TRAINING_VIEW_FEATURES, RequestType.GET,
185+
self._basic_auth, { "view": training_view })
188186
return [Feature(**f) for f in r]
189187

190188
def get_feature_description(self):
@@ -601,6 +599,28 @@ def get_training_set_features(self, training_set: str = None):
601599
r['features'] = [Feature(**f) for f in r['features']]
602600
return r
603601

602+
def remove_feature_set(self, schema: str, table: str, purge: bool = False) -> None:
603+
"""
604+
Deletes a feature set if appropriate. You can currently delete a feature set in two scenarios:
605+
1. The feature set has not been deployed
606+
2. The feature set has been deployed, but not linked to any training sets
607+
608+
If both of these conditions are false, this will fail.
609+
610+
Optionally set purge=True to force delete the feature set and all of the associated Training Sets using the
611+
Feature Set. ONLY USE IF YOU KNOW WHAT YOU ARE DOING. This will delete Training Sets, but will still fail if
612+
there is an active deployment with this feature set. That cannot be overwritten
613+
614+
:param schema: The Feature Set Schema
615+
:param table: The Feature Set Table
616+
:param purge: Whether to force delete training sets that use the feature set (that are not used in deployments)
617+
"""
618+
if purge:
619+
warnings.warn("You've set purge=True, I hope you know what you are doing! This will delete any dependent"
620+
" Training Sets (except ones used in an active model deployment)")
621+
make_request(self._FS_URL, Endpoints.FEATURE_SETS,
622+
RequestType.DELETE, self._basic_auth, { "schema": schema, "table":table, "purge": purge })
623+
604624
def _retrieve_model_data_sets(self, schema_name: str, table_name: str):
605625
"""
606626
Returns the training set dataframe and model table dataframe for a given deployed model.

splicemachine/features/utils/http_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Dict, Union, Tuple
1+
from typing import List, Dict, Union, Tuple, Optional, Any
22
import requests
33
from splicemachine import SpliceMachineException
44
from os import environ as env_vars
@@ -45,7 +45,9 @@ class Endpoints:
4545
TRAINING_VIEW_ID: str = "training-view-id"
4646
SUMMARY: str = "summary"
4747

48-
def make_request(url: str, endpoint: str, method: str, auth: HTTPBasicAuth, params: Dict[str, Union[str, List[Union[str, int]]]] = None, body: Dict[str, str] = None) -> Union[dict,List[dict]]:
48+
def make_request(url: str, endpoint: str, method: str, auth: HTTPBasicAuth,
49+
params: Optional[Dict[str, Any]] = None,
50+
body: Union[Dict[str,Any], List[Any]] = None) -> Union[dict,List[dict]]:
4951
if not auth:
5052
raise Exception(
5153
"You have not logged into Feature Store director."

0 commit comments

Comments
 (0)