Skip to content

Commit 867a179

Browse files
Select all Features of a Feature Group except few (#207)
1 parent f356072 commit 867a179

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

java/src/main/java/com/logicalclocks/hsfs/metadata/FeatureGroupBase.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,31 @@ public FeatureGroupBase(FeatureStore featureStore, Integer id) {
7575
this.id = id;
7676
}
7777

78-
public Query selectFeatures(List<Feature> features) throws FeatureStoreException, IOException {
78+
public Query selectFeatures(List<Feature> features) {
7979
return new Query(this, features);
8080
}
8181

82-
public Query select(List<String> features) throws FeatureStoreException, IOException {
82+
public Query select(List<String> features) {
8383
// Create a feature object for each string feature given by the user.
8484
// For the query building each feature need only the name set.
8585
List<Feature> featureObjList = features.stream().map(Feature::new).collect(Collectors.toList());
8686
return selectFeatures(featureObjList);
8787
}
8888

89-
public Query selectAll() throws FeatureStoreException, IOException {
89+
public Query selectAll() {
9090
return new Query(this, getFeatures());
9191
}
9292

93+
public Query selectExceptFeatures(List<Feature> features) {
94+
List<String> exceptFeatures = features.stream().map(Feature::getName).collect(Collectors.toList());
95+
return selectExcept(exceptFeatures);
96+
}
97+
98+
public Query selectExcept(List<String> features) {
99+
return new Query(this,
100+
getFeatures().stream().filter(f -> !features.contains(f.getName())).collect(Collectors.toList()));
101+
}
102+
93103
public void delete() throws FeatureStoreException, IOException {
94104
featureGroupBaseEngine.delete(this);
95105
}

python/hsfs/feature_group.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def select_all(self):
6565
self._feature_store_name, self._feature_store_id, self, self._features
6666
)
6767

68-
def select(self, features=[]):
68+
def select(self, features: List[Union[str, feature.Feature]] = []):
6969
"""Select a subset of features of the feature group and return a query object.
7070
7171
The query can be used to construct joins of feature groups or create a training
@@ -82,6 +82,33 @@ def select(self, features=[]):
8282
self._feature_store_name, self._feature_store_id, self, features
8383
)
8484

85+
def select_except(self, features: List[Union[str, feature.Feature]] = []):
86+
"""Select all features of the feature group except a few and return a query
87+
object.
88+
89+
The query can be used to construct joins of feature groups or create a training
90+
dataset with a subset of features of the feature group.
91+
92+
# Arguments
93+
features: list, optional. A list of `Feature` objects or feature names as
94+
strings to be selected, defaults to [], selecting all features.
95+
96+
# Returns
97+
`Query`: A query object with the selected features of the feature group.
98+
"""
99+
if features:
100+
except_features = [
101+
f.name if isinstance(f, feature.Feature) else f for f in features
102+
]
103+
return query.Query(
104+
self._feature_store_name,
105+
self._feature_store_id,
106+
self,
107+
[f for f in self._features if f.name not in except_features],
108+
)
109+
else:
110+
return self.select_all()
111+
85112
def filter(self, f: Union[filter.Filter, filter.Logic]):
86113
"""Apply filter to the feature group.
87114

0 commit comments

Comments
 (0)