Skip to content

Commit a8144dd

Browse files
refactor: Delete unnecessary errors.go file (feast-dev#2392)
* Clean up docstrings Signed-off-by: Felix Wang <wangfelix98@gmail.com> * Move featureNameCollisionError from errors.go into featurestore.go Signed-off-by: Felix Wang <wangfelix98@gmail.com>
1 parent 0bb5e8c commit a8144dd

3 files changed

Lines changed: 52 additions & 55 deletions

File tree

go/internal/feast/errors.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

go/internal/feast/featurestore.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -401,52 +401,51 @@ func (fs *FeatureStore) validateEntityValues(joinKeyValues map[string]*types.Rep
401401
}
402402

403403
func (fs *FeatureStore) validateFeatureRefs(featureRefs []string, fullFeatureNames bool) error {
404-
collidedFeatureRefs := make(map[string]int)
404+
featureRefCounter := make(map[string]int)
405405
if fullFeatureNames {
406406
for _, featureRef := range featureRefs {
407-
collidedFeatureRefs[featureRef] += 1
407+
featureRefCounter[featureRef]++
408408
}
409-
for featureName, occurrences := range collidedFeatureRefs {
409+
for featureName, occurrences := range featureRefCounter {
410410
if occurrences == 1 {
411-
delete(collidedFeatureRefs, featureName)
411+
delete(featureRefCounter, featureName)
412412
}
413413
}
414-
if len(collidedFeatureRefs) >= 1 {
415-
collidedFeatureRefList := make([]string, len(collidedFeatureRefs))
414+
if len(featureRefCounter) >= 1 {
415+
collidedFeatureRefs := make([]string, len(featureRefCounter))
416416
index := 0
417-
for featureName := range collidedFeatureRefs {
418-
collidedFeatureRefList[index] = featureName
419-
index += 1
417+
for collidedFeatureRef := range featureRefCounter {
418+
collidedFeatureRefs[index] = collidedFeatureRef
419+
index++
420420
}
421-
return NewFeatureNameCollisionError(collidedFeatureRefList, fullFeatureNames)
421+
return featureNameCollisionError{collidedFeatureRefs, fullFeatureNames}
422422
}
423423
} else {
424424
for _, featureRef := range featureRefs {
425425
_, featureName, err := parseFeatureReference(featureRef)
426426
if err != nil {
427427
return err
428428
}
429-
collidedFeatureRefs[featureName] += 1
429+
featureRefCounter[featureName]++
430430
}
431-
432-
for featureName, occurrences := range collidedFeatureRefs {
431+
for featureName, occurrences := range featureRefCounter {
433432
if occurrences == 1 {
434-
delete(collidedFeatureRefs, featureName)
433+
delete(featureRefCounter, featureName)
435434
}
436435
}
437-
if len(collidedFeatureRefs) >= 1 {
438-
collidedFeatureRefList := make([]string, 0)
436+
if len(featureRefCounter) >= 1 {
437+
collidedFeatureRefs := make([]string, 0)
439438
for _, featureRef := range featureRefs {
440439
_, featureName, err := parseFeatureReference(featureRef)
441440
if err != nil {
442441
return err
443442
}
444-
if _, ok := collidedFeatureRefs[featureName]; ok {
445-
collidedFeatureRefList = append(collidedFeatureRefList, featureRef)
443+
if _, ok := featureRefCounter[featureName]; ok {
444+
collidedFeatureRefs = append(collidedFeatureRefs, featureRef)
446445
}
447446

448447
}
449-
return errors.New(fmt.Sprintf("featureNameCollisionError: %s; %t", strings.Join(collidedFeatureRefList, ", "), fullFeatureNames))
448+
return featureNameCollisionError{collidedFeatureRefs, fullFeatureNames}
450449
}
451450
}
452451
return nil
@@ -858,3 +857,12 @@ func getFeatureResponseMeta(featureNameAlias string, featureName string, fullFea
858857
return featureName
859858
}
860859
}
860+
861+
type featureNameCollisionError struct {
862+
featureRefCollisions []string
863+
fullFeatureNames bool
864+
}
865+
866+
func (e featureNameCollisionError) Error() string {
867+
return fmt.Sprintf("featureNameCollisionError: %s; %t", strings.Join(e.featureRefCollisions, ", "), e.fullFeatureNames)
868+
}

sdk/python/feast/feature_store.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -784,12 +784,12 @@ def get_historical_features(
784784
columns (e.g., customer_id, driver_id) on which features need to be joined, as well as a event_timestamp
785785
column used to ensure point-in-time correctness. Either a Pandas DataFrame can be provided or a string
786786
SQL query. The query must be of a format supported by the configured offline store (e.g., BigQuery)
787-
features: A list of features, that should be retrieved from the offline store.
788-
Either a list of string feature references can be provided or a FeatureService object.
789-
Feature references are of the format "feature_view:feature", e.g., "customer_fv:daily_transactions".
790-
full_feature_names: A boolean that provides the option to add the feature view prefixes to the feature names,
791-
changing them from the format "feature" to "feature_view__feature" (e.g., "daily_transactions" changes to
792-
"customer_fv__daily_transactions"). By default, this value is set to False.
787+
features: The list of features that should be retrieved from the offline store. These features can be
788+
specified either as a list of string feature references or as a feature service. String feature
789+
references must have format "feature_view:feature", e.g. "customer_fv:daily_transactions".
790+
full_feature_names: If True, feature names will be prefixed with the corresponding feature view name,
791+
changing them from the format "feature" to "feature_view__feature" (e.g. "daily_transactions"
792+
changes to "customer_fv__daily_transactions").
793793
794794
Returns:
795795
RetrievalJob which can be used to materialize the results.
@@ -822,7 +822,6 @@ def get_historical_features(
822822
... )
823823
>>> feature_data = retrieval_job.to_df()
824824
"""
825-
826825
_feature_refs = self._get_features(features)
827826
(
828827
all_feature_views,
@@ -1194,12 +1193,13 @@ def get_online_features(
11941193
infinity (cache forever).
11951194
11961195
Args:
1197-
features: List of feature references that will be returned for each entity.
1198-
Each feature reference should have the following format:
1199-
"feature_view:feature" where "feature_view" & "feature" refer to
1200-
the Feature and FeatureView names respectively.
1201-
Only the feature name is required.
1196+
features: The list of features that should be retrieved from the online store. These features can be
1197+
specified either as a list of string feature references or as a feature service. String feature
1198+
references must have format "feature_view:feature", e.g. "customer_fv:daily_transactions".
12021199
entity_rows: A list of dictionaries where each key-value is an entity-name, entity-value pair.
1200+
full_feature_names: If True, feature names will be prefixed with the corresponding feature view name,
1201+
changing them from the format "feature" to "feature_view__feature" (e.g. "daily_transactions"
1202+
changes to "customer_fv__daily_transactions").
12031203
12041204
Returns:
12051205
OnlineResponse containing the feature data in records.
@@ -1870,16 +1870,26 @@ def _validate_entity_values(join_key_values: Dict[str, List[Value]]):
18701870

18711871

18721872
def _validate_feature_refs(feature_refs: List[str], full_feature_names: bool = False):
1873+
"""
1874+
Validates that there are no collisions among the feature references.
1875+
1876+
Args:
1877+
feature_refs: List of feature references to validate. Feature references must have format
1878+
"feature_view:feature", e.g. "customer_fv:daily_transactions".
1879+
full_feature_names: If True, the full feature references are compared for collisions; if False,
1880+
only the feature names are compared.
1881+
1882+
Raises:
1883+
FeatureNameCollisionError: There is a collision among the feature references.
1884+
"""
18731885
collided_feature_refs = []
18741886

18751887
if full_feature_names:
18761888
collided_feature_refs = [
18771889
ref for ref, occurrences in Counter(feature_refs).items() if occurrences > 1
18781890
]
18791891
else:
1880-
feature_names = [
1881-
ref.split(":")[1] if ":" in ref else ref for ref in feature_refs
1882-
]
1892+
feature_names = [ref.split(":")[1] for ref in feature_refs]
18831893
collided_feature_names = [
18841894
ref
18851895
for ref, occurrences in Counter(feature_names).items()

0 commit comments

Comments
 (0)