Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,31 @@ public FeatureGroupBase(FeatureStore featureStore, Integer id) {
this.id = id;
}

public Query selectFeatures(List<Feature> features) throws FeatureStoreException, IOException {
public Query selectFeatures(List<Feature> features) {
return new Query(this, features);
}

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

public Query selectAll() throws FeatureStoreException, IOException {
public Query selectAll() {
return new Query(this, getFeatures());
}

public Query selectExceptFeatures(List<Feature> features) {
List<String> exceptFeatures = features.stream().map(Feature::getName).collect(Collectors.toList());
return selectExcept(exceptFeatures);
}

public Query selectExcept(List<String> features) {
return new Query(this,
getFeatures().stream().filter(f -> !features.contains(f.getName())).collect(Collectors.toList()));
}

public void delete() throws FeatureStoreException, IOException {
featureGroupBaseEngine.delete(this);
}
Expand Down
29 changes: 28 additions & 1 deletion python/hsfs/feature_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def select_all(self):
self._feature_store_name, self._feature_store_id, self, self._features
)

def select(self, features=[]):
def select(self, features: List[Union[str, feature.Feature]] = []):
"""Select a subset of features of the feature group and return a query object.

The query can be used to construct joins of feature groups or create a training
Expand All @@ -82,6 +82,33 @@ def select(self, features=[]):
self._feature_store_name, self._feature_store_id, self, features
)

def select_except(self, features: List[Union[str, feature.Feature]] = []):
"""Select all features of the feature group except a few and return a query
object.

The query can be used to construct joins of feature groups or create a training
dataset with a subset of features of the feature group.

# Arguments
features: list, optional. A list of `Feature` objects or feature names as
strings to be selected, defaults to [], selecting all features.

# Returns
`Query`: A query object with the selected features of the feature group.
"""
if features:
except_features = [
f.name if isinstance(f, feature.Feature) else f for f in features
]
return query.Query(
self._feature_store_name,
self._feature_store_id,
self,
[f for f in self._features if f.name not in except_features],
)
else:
return self.select_all()

def filter(self, f: Union[filter.Filter, filter.Logic]):
"""Apply filter to the feature group.

Expand Down