Skip to content

Commit a72e212

Browse files
committed
Serving should not throw exception when key not found in Redis
1 parent 28f02d2 commit a72e212

2 files changed

Lines changed: 17 additions & 27 deletions

File tree

serving/src/main/java/feast/serving/service/RedisServingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ private List<byte[]> sendMultiGet(List<RedisKey> keys) {
328328
.collect(Collectors.toList())
329329
.toArray(new byte[0][0]);
330330
return syncCommands.mget(binaryKeys).stream()
331-
.map(io.lettuce.core.Value::getValue)
331+
.map(keyValue -> keyValue.getValueOrElse(null))
332332
.collect(Collectors.toList());
333333
} catch (Exception e) {
334334
throw Status.NOT_FOUND

serving/src/test/java/feast/serving/service/RedisServingServiceTest.java

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -377,39 +377,29 @@ public void shouldReturnResponseWithUnsetValuesIfKeysNotPresent() {
377377
.putFields("entity2", strValue("b")))
378378
.build();
379379

380-
List<FeatureRow> featureRows =
381-
Lists.newArrayList(
382-
FeatureRow.newBuilder()
383-
.setEventTimestamp(Timestamp.newBuilder().setSeconds(100))
384-
.addAllFields(
385-
Lists.newArrayList(
386-
Field.newBuilder().setName("entity1").setValue(intValue(1)).build(),
387-
Field.newBuilder().setName("entity2").setValue(strValue("a")).build(),
388-
Field.newBuilder().setName("feature1").setValue(intValue(1)).build(),
389-
Field.newBuilder().setName("feature2").setValue(intValue(1)).build()))
390-
.setFeatureSet("featureSet:1")
391-
.build(),
392-
FeatureRow.newBuilder()
393-
.setEventTimestamp(Timestamp.newBuilder())
394-
.addAllFields(
395-
Lists.newArrayList(
396-
Field.newBuilder().setName("entity1").setValue(intValue(2)).build(),
397-
Field.newBuilder().setName("entity2").setValue(strValue("b")).build(),
398-
Field.newBuilder().setName("feature1").build(),
399-
Field.newBuilder().setName("feature2").build()))
400-
.setFeatureSet("featureSet:1")
401-
.build());
402-
403380
FeatureSetRequest featureSetRequest =
404381
FeatureSetRequest.newBuilder()
405382
.addAllFeatureReferences(request.getFeaturesList())
406383
.setSpec(getFeatureSetSpec())
407384
.build();
408385

386+
FeatureRow featureRowPresent =
387+
FeatureRow.newBuilder()
388+
.setEventTimestamp(Timestamp.newBuilder().setSeconds(100))
389+
.addAllFields(
390+
Lists.newArrayList(
391+
Field.newBuilder().setName("entity1").setValue(intValue(1)).build(),
392+
Field.newBuilder().setName("entity2").setValue(strValue("a")).build(),
393+
Field.newBuilder().setName("feature1").setValue(intValue(1)).build(),
394+
Field.newBuilder().setName("feature2").setValue(intValue(1)).build()))
395+
.setFeatureSet("featureSet:1")
396+
.build();
397+
409398
List<KeyValue<byte[], byte[]>> featureRowBytes =
410-
featureRows.stream()
411-
.map(x -> KeyValue.from(new byte[1], Optional.of(x.toByteArray())))
412-
.collect(Collectors.toList());
399+
Lists.newArrayList(
400+
KeyValue.from(new byte[1], Optional.of(featureRowPresent.toByteArray())),
401+
KeyValue.from(new byte[1], Optional.empty()));
402+
413403
when(specService.getFeatureSets(request.getFeaturesList()))
414404
.thenReturn(Collections.singletonList(featureSetRequest));
415405
when(connection.sync()).thenReturn(syncCommands);

0 commit comments

Comments
 (0)