Skip to content

Commit 56ede26

Browse files
committed
entities order as in spec
Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com>
1 parent d6c98b5 commit 56ede26

5 files changed

Lines changed: 51 additions & 49 deletions

File tree

‎serving/src/main/java/feast/serving/service/OnlineServingServiceV2.java‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import static feast.common.models.FeatureTable.getFeatureTableStringRef;
2020

2121
import com.google.protobuf.Duration;
22+
import com.google.protobuf.ProtocolStringList;
2223
import feast.common.models.FeatureV2;
24+
import feast.proto.core.FeatureTableProto;
2325
import feast.proto.serving.ServingAPIProto.FeastServingType;
2426
import feast.proto.serving.ServingAPIProto.FeatureReferenceV2;
2527
import feast.proto.serving.ServingAPIProto.GetFeastServingInfoRequest;
@@ -89,31 +91,12 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequestV2 re
8991
entry.getKey(),
9092
// TODO: Is there a better default value to set
9193
getMetadata(
92-
ValueProto.Value.newBuilder().setStringVal("").build(),
93-
false,
94+
ValueProto.Value.newBuilder().build(),
95+
true,
9496
false)))
9597
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight)))
9698
.collect(Collectors.toList());
9799

98-
Span storageRetrievalSpan = tracer.buildSpan("storageRetrieval").start();
99-
if (storageRetrievalSpan != null) {
100-
storageRetrievalSpan.setTag("entities", entityRows.size());
101-
storageRetrievalSpan.setTag("features", featureReferences.size());
102-
}
103-
List<List<Feature>> entityRowsFeatures =
104-
retriever.getOnlineFeatures(projectName, entityRows, featureReferences);
105-
if (storageRetrievalSpan != null) {
106-
storageRetrievalSpan.finish();
107-
}
108-
109-
if (entityRowsFeatures.size() != entityRows.size()) {
110-
throw Status.INTERNAL
111-
.withDescription(
112-
"The no. of FeatureRow obtained from OnlineRetriever"
113-
+ "does not match no. of entityRow passed.")
114-
.asRuntimeException();
115-
}
116-
117100
String finalProjectName = projectName;
118101
Map<FeatureReferenceV2, Duration> featureMaxAges =
119102
featureReferences.stream()
@@ -122,6 +105,9 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequestV2 re
122105
Collectors.toMap(
123106
Function.identity(),
124107
ref -> specService.getFeatureTableSpec(finalProjectName, ref).getMaxAge()));
108+
List<String> entityNames = featureReferences.stream().map(
109+
ref -> specService.getFeatureTableSpec(finalProjectName, ref).getEntitiesList()
110+
).findFirst().get();
125111

126112
Map<FeatureReferenceV2, ValueProto.ValueType.Enum> featureValueTypes =
127113
featureReferences.stream()
@@ -137,6 +123,25 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequestV2 re
137123
}
138124
}));
139125

126+
Span storageRetrievalSpan = tracer.buildSpan("storageRetrieval").start();
127+
if (storageRetrievalSpan != null) {
128+
storageRetrievalSpan.setTag("entities", entityRows.size());
129+
storageRetrievalSpan.setTag("features", featureReferences.size());
130+
}
131+
List<List<Feature>> entityRowsFeatures =
132+
retriever.getOnlineFeatures(projectName, entityRows, featureReferences, entityNames);
133+
if (storageRetrievalSpan != null) {
134+
storageRetrievalSpan.finish();
135+
}
136+
137+
if (entityRowsFeatures.size() != entityRows.size()) {
138+
throw Status.INTERNAL
139+
.withDescription(
140+
"The no. of FeatureRow obtained from OnlineRetriever"
141+
+ "does not match no. of entityRow passed.")
142+
.asRuntimeException();
143+
}
144+
140145
Span postProcessingSpan = tracer.buildSpan("postProcessing").start();
141146

142147
for (int i = 0; i < entityRows.size(); i++) {

‎serving/src/test/java/feast/serving/service/OnlineServingServiceTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void shouldReturnResponseWithValuesAndMetadataIfKeysPresent() {
152152

153153
List<List<Feature>> featureRows = List.of(entityKeyList1, entityKeyList2);
154154

155-
when(retrieverV2.getOnlineFeatures(any(), any(), any())).thenReturn(featureRows);
155+
when(retrieverV2.getOnlineFeatures(any(), any(), any(), any())).thenReturn(featureRows);
156156
when(specService.getFeatureTableSpec(any(), any())).thenReturn(getFeatureTableSpec());
157157
when(specService.getFeatureSpec(projectName, mockedFeatureRows.get(0).getFeatureReference()))
158158
.thenReturn(featureSpecs.get(0));
@@ -219,7 +219,7 @@ public void shouldReturnResponseWithUnsetValuesAndMetadataIfKeysNotPresent() {
219219

220220
List<List<Feature>> featureRows = List.of(entityKeyList1, entityKeyList2);
221221

222-
when(retrieverV2.getOnlineFeatures(any(), any(), any())).thenReturn(featureRows);
222+
when(retrieverV2.getOnlineFeatures(any(), any(), any(), any())).thenReturn(featureRows);
223223
when(specService.getFeatureTableSpec(any(), any())).thenReturn(getFeatureTableSpec());
224224
when(specService.getFeatureSpec(projectName, mockedFeatureRows.get(0).getFeatureReference()))
225225
.thenReturn(featureSpecs.get(0));
@@ -283,7 +283,7 @@ public void shouldReturnResponseWithUnsetValuesAndMetadataIfMaxAgeIsExceeded() {
283283

284284
List<List<Feature>> featureRows = List.of(entityKeyList1, entityKeyList2);
285285

286-
when(retrieverV2.getOnlineFeatures(any(), any(), any())).thenReturn(featureRows);
286+
when(retrieverV2.getOnlineFeatures(any(), any(), any(), any())).thenReturn(featureRows);
287287
when(specService.getFeatureTableSpec(any(), any()))
288288
.thenReturn(
289289
FeatureTableSpec.newBuilder()

‎storage/api/src/main/java/feast/storage/api/retriever/OnlineRetrieverV2.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ public interface OnlineRetrieverV2 {
3939
List<List<Feature>> getOnlineFeatures(
4040
String project,
4141
List<ServingAPIProto.GetOnlineFeaturesRequestV2.EntityRow> entityRows,
42-
List<ServingAPIProto.FeatureReferenceV2> featureReferences);
42+
List<ServingAPIProto.FeatureReferenceV2> featureReferences,
43+
List<String> entityNames);
4344
}

‎storage/connectors/bigtable/src/main/java/feast/storage/connectors/bigtable/retriever/BigTableOnlineRetriever.java‎

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import feast.storage.api.retriever.NativeFeature;
3131
import feast.storage.api.retriever.OnlineRetrieverV2;
3232
import java.io.IOException;
33-
import java.util.ArrayList;
34-
import java.util.HashSet;
3533
import java.util.List;
3634
import java.util.Objects;
3735
import java.util.stream.Collectors;
@@ -52,9 +50,7 @@ public BigTableOnlineRetriever(BigtableDataClient client) {
5250
this.schemaRegistry = new BigTableSchemaRegistry(client);
5351
}
5452

55-
private String getTableName(String project, EntityRow entityRow) {
56-
List<String> entityNames = new ArrayList<>(new HashSet<>(entityRow.getFieldsMap().keySet()));
57-
53+
private String getTableName(String project, List<String> entityNames) {
5854
String tableName =
5955
String.format("%s__%s", project, entityNames.stream().collect(Collectors.joining("__")));
6056

@@ -83,12 +79,7 @@ private String valueToString(ValueProto.Value v) {
8379
return stringRepr;
8480
}
8581

86-
private ByteString convertEntityValueToBigTableKey(EntityRow entityRow) {
87-
List<String> entityNames = new ArrayList<>(new HashSet<>(entityRow.getFieldsMap().keySet()));
88-
89-
// Sort entity names by alphabetical order
90-
entityNames.sort(String::compareTo);
91-
82+
private ByteString convertEntityValueToBigTableKey(EntityRow entityRow, List<String> entityNames) {
9283
return ByteString.copyFrom(
9384
entityNames.stream()
9485
.map(entity -> entityRow.getFieldsMap().get(entity))
@@ -124,17 +115,18 @@ private List<Feature> decodeFeatures(
124115
return featureReferences.stream()
125116
.map(
126117
featureReference -> {
118+
Object featureValue;
127119
try {
128-
Object featureValue = record.get(featureReference.getName());
129-
if (featureValue != null) {
130-
return new NativeFeature(
131-
featureReference,
132-
Timestamp.newBuilder().setSeconds(timestamp / 1000).build(),
133-
featureValue);
134-
}
120+
featureValue = record.get(featureReference.getName());
135121
} catch (AvroRuntimeException e) {
136122
return null;
137123
}
124+
if (featureValue != null) {
125+
return new NativeFeature(
126+
featureReference,
127+
Timestamp.newBuilder().setSeconds(timestamp / 1000).build(),
128+
featureValue);
129+
}
138130
return null;
139131
})
140132
.filter(Objects::nonNull)
@@ -143,27 +135,30 @@ private List<Feature> decodeFeatures(
143135

144136
@Override
145137
public List<List<Feature>> getOnlineFeatures(
146-
String project, List<EntityRow> entityRows, List<FeatureReferenceV2> featureReferences) {
138+
String project,
139+
List<EntityRow> entityRows,
140+
List<FeatureReferenceV2> featureReferences,
141+
List<String> entityNames) {
147142
List<String> columnFamilies = getColumnFamilies(featureReferences);
148-
String tableName = getTableName(project, entityRows.get(0));
143+
String tableName = getTableName(project, entityNames);
149144

150145
ServerStream<Row> rowsFromBigTable =
151-
getFeaturesFromBigTable(tableName, entityRows, columnFamilies);
146+
getFeaturesFromBigTable(tableName, entityRows, columnFamilies, entityNames);
152147
List<List<Feature>> features =
153148
convertRowToFeature(tableName, rowsFromBigTable, featureReferences);
154149

155150
return features;
156151
}
157152

158153
private ServerStream<Row> getFeaturesFromBigTable(
159-
String tableName, List<EntityRow> entityRows, List<String> columnFamilies) {
154+
String tableName, List<EntityRow> entityRows, List<String> columnFamilies, List<String> entityNames) {
160155

161156
Query rowQuery = Query.create(tableName);
162157
Filters.InterleaveFilter familyFilter = Filters.FILTERS.interleave();
163158
columnFamilies.forEach(cf -> familyFilter.filter(Filters.FILTERS.family().exactMatch(cf)));
164159

165160
for (EntityRow row : entityRows) {
166-
ByteString rowKey = convertEntityValueToBigTableKey(row);
161+
ByteString rowKey = convertEntityValueToBigTableKey(row, entityNames);
167162
rowQuery = rowQuery.rowKey(rowKey);
168163
}
169164

‎storage/connectors/redis/src/main/java/feast/storage/connectors/redis/retriever/OnlineRetriever.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public OnlineRetriever(RedisClientAdapter redisClientAdapter) {
4444
public List<List<Feature>> getOnlineFeatures(
4545
String project,
4646
List<ServingAPIProto.GetOnlineFeaturesRequestV2.EntityRow> entityRows,
47-
List<ServingAPIProto.FeatureReferenceV2> featureReferences) {
47+
List<ServingAPIProto.FeatureReferenceV2> featureReferences,
48+
List<String> entityNames) {
4849

4950
List<RedisProto.RedisKeyV2> redisKeys = RedisKeyGenerator.buildRedisKeys(project, entityRows);
5051
List<List<Feature>> features = getFeaturesFromRedis(redisKeys, featureReferences);

0 commit comments

Comments
 (0)