Skip to content

Commit 3d12dbf

Browse files
committed
fix error to search with key instead of name
1 parent e093be7 commit 3d12dbf

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

go/internal/feast/featurestore.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,15 @@ func (fs *FeatureStore) ListEntities(hideDummyEntity bool) ([]*model.Entity, err
291291
return entities, nil
292292
}
293293

294-
func (fs *FeatureStore) ListEntity(entityName string) (*model.Entity, error) {
294+
func (fs *FeatureStore) ListEntityByJoinKey(entitykey string) (*model.Entity, error) {
295295

296-
entity, err := fs.registry.GetEntity(fs.config.Project, entityName)
297-
if err != nil {
298-
return entity, err
296+
entities, _ := fs.ListEntities(false)
297+
for _, entity := range entities {
298+
if entity.JoinKey == entitykey {
299+
return entity, nil
300+
}
299301
}
300-
return entity, nil
302+
return nil, fmt.Errorf("entity with join key %s not found", entitykey)
301303
}
302304

303305
func (fs *FeatureStore) ListOnDemandFeatureViews() ([]*model.OnDemandFeatureView, error) {

go/internal/feast/server/http_server.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ func logWithSpanContext(span tracer.Span) zerolog.Logger {
171171

172172
/*
173173
*
174-
This function is to typecast entity values unmarshalled from JSON to the actual entity type specified in the entity definition.
175-
This is because of a bug when using an entity defined with ValueType_INT32
174+
This function fixes the bug when the entity join key type is INT32.
175+
It typecasts the entity values to int32, as unmarshalled JSON values only return int64.
176176
*/
177-
func typecastToEntityIntType(val *repeatedValue, entityType prototypes.ValueType_Enum) {
177+
func typecastToInt32Type(val *repeatedValue, entityType prototypes.ValueType_Enum) {
178178
if val.int64Val != nil {
179179
if entityType == prototypes.ValueType_INT32 {
180180
for _, v := range val.int64Val {
@@ -183,14 +183,6 @@ func typecastToEntityIntType(val *repeatedValue, entityType prototypes.ValueType
183183
val.int64Val = nil
184184
}
185185
}
186-
if val.int32Val != nil {
187-
if entityType == prototypes.ValueType_INT64 {
188-
for _, v := range val.int32Val {
189-
val.int64Val = append(val.int64Val, int64(v))
190-
}
191-
val.int32Val = nil
192-
}
193-
}
194186
}
195187

196188
func (s *httpServer) getOnlineFeatures(w http.ResponseWriter, r *http.Request) {
@@ -238,11 +230,15 @@ func (s *httpServer) getOnlineFeatures(w http.ResponseWriter, r *http.Request) {
238230
}
239231
entitiesProto := make(map[string]*prototypes.RepeatedValue)
240232
for key, value := range request.Entities {
241-
var entity, err = s.fs.ListEntity(key)
233+
var entity, err = s.fs.ListEntityByJoinKey(key)
242234
if err != nil {
243-
235+
logSpanContext.Error().Err(err).Msg("Error getting entity from registry")
236+
writeJSONError(w, fmt.Errorf("Error getting entity from registry: %+v", err), http.StatusInternalServerError)
237+
return
238+
}
239+
if value.int64Val != nil {
240+
typecastToInt32Type(&value, entity.Dtype)
244241
}
245-
typecastToEntityIntType(&value, entity.Dtype)
246242
entitiesProto[key] = value.ToProto()
247243
}
248244
requestContextProto := make(map[string]*prototypes.RepeatedValue)

0 commit comments

Comments
 (0)