Skip to content

Commit 986e337

Browse files
author
Chen Zhiling
committed
Add better code docs to storage refactor (#601)
* Add better code documentation, make GetFeastServingInfo independent of retriever * Make getStagingLocation method of historical retriever * Apply spotless
1 parent 4874725 commit 986e337

File tree

5 files changed

+94
-14
lines changed

5 files changed

+94
-14
lines changed

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import feast.storage.api.retrieval.FeatureSetRequest;
2424
import feast.storage.api.retrieval.HistoricalRetrievalResult;
2525
import feast.storage.api.retrieval.HistoricalRetriever;
26-
import feast.storage.connectors.bigquery.retrieval.BigQueryHistoricalRetriever;
2726
import io.grpc.Status;
2827
import java.util.List;
2928
import java.util.Optional;
@@ -50,18 +49,10 @@ public HistoricalServingService(
5049
@Override
5150
public GetFeastServingInfoResponse getFeastServingInfo(
5251
GetFeastServingInfoRequest getFeastServingInfoRequest) {
53-
try {
54-
BigQueryHistoricalRetriever bigQueryHistoricalRetriever =
55-
(BigQueryHistoricalRetriever) retriever;
56-
return GetFeastServingInfoResponse.newBuilder()
57-
.setType(FeastServingType.FEAST_SERVING_TYPE_BATCH)
58-
.setJobStagingLocation(bigQueryHistoricalRetriever.jobStagingLocation())
59-
.build();
60-
} catch (Exception e) {
61-
return GetFeastServingInfoResponse.newBuilder()
62-
.setType(FeastServingType.FEAST_SERVING_TYPE_BATCH)
63-
.build();
64-
}
52+
return GetFeastServingInfoResponse.newBuilder()
53+
.setType(FeastServingType.FEAST_SERVING_TYPE_BATCH)
54+
.setJobStagingLocation(retriever.getStagingLocation())
55+
.build();
6556
}
6657

6758
/** {@inheritDoc} */

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,32 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequest requ
7474
Map<EntityRow, Map<String, Value>> featureValuesMap =
7575
entityRows.stream()
7676
.collect(Collectors.toMap(row -> row, row -> Maps.newHashMap(row.getFieldsMap())));
77-
77+
// Get all feature rows from the retriever. Each feature row list corresponds to a single
78+
// feature set request.
7879
List<List<FeatureRow>> featureRows =
7980
retriever.getOnlineFeatures(entityRows, featureSetRequests);
8081

82+
// For each feature set request, read the feature rows returned by the retriever, and
83+
// populate the featureValuesMap with the feature values corresponding to that entity row.
8184
for (var fsIdx = 0; fsIdx < featureRows.size(); fsIdx++) {
8285
List<FeatureRow> featureRowsForFs = featureRows.get(fsIdx);
8386
FeatureSetRequest featureSetRequest = featureSetRequests.get(fsIdx);
87+
88+
// In order to return values containing the same feature references provided by the user,
89+
// we reuse the feature references in the request as the keys in the featureValuesMap
8490
Map<String, FeatureReference> featureNames =
8591
featureSetRequest.getFeatureReferences().stream()
8692
.collect(
8793
Collectors.toMap(
8894
FeatureReference::getName, featureReference -> featureReference));
95+
96+
// Each feature row returned (per feature set request) corresponds to a given entity row.
97+
// For each feature row, update the featureValuesMap.
8998
for (var entityRowIdx = 0; entityRowIdx < entityRows.size(); entityRowIdx++) {
9099
FeatureRow featureRow = featureRowsForFs.get(entityRowIdx);
91100
EntityRow entityRow = entityRows.get(entityRowIdx);
101+
102+
// If the row is stale, put an empty value into the featureValuesMap.
92103
if (isStale(featureSetRequest, entityRow, featureRow)) {
93104
featureSetRequest
94105
.getFeatureReferences()
@@ -117,6 +128,8 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequest requ
117128
String.format("%s:%d", ref.getName(), ref.getVersion()))
118129
.inc());
119130

131+
// Else populate the featureValueMap at this entityRow with the values in the feature
132+
// row.
120133
featureRow.getFieldsList().stream()
121134
.filter(field -> featureNames.containsKey(field.getName()))
122135
.forEach(

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,75 @@
2626
import feast.serving.ServingAPIProto.GetOnlineFeaturesResponse;
2727

2828
public interface ServingService {
29+
/**
30+
* Get information about the Feast serving deployment.
31+
*
32+
* <p>For Bigquery deployments, this includes the default job staging location to load
33+
* intermediate files to. Otherwise, this method only returns the current Feast Serving backing
34+
* store type.
35+
*
36+
* @param getFeastServingInfoRequest {@link GetFeastServingInfoRequest}
37+
* @return {@link GetFeastServingInfoResponse}
38+
*/
2939
GetFeastServingInfoResponse getFeastServingInfo(
3040
GetFeastServingInfoRequest getFeastServingInfoRequest);
3141

42+
/**
43+
* Get features from an online serving store, given a list of {@link
44+
* feast.serving.ServingAPIProto.FeatureReference}s to retrieve, and list of {@link
45+
* feast.serving.ServingAPIProto.GetOnlineFeaturesRequest.EntityRow}s to join the retrieved values
46+
* to.
47+
*
48+
* <p>Features can be queried across feature sets, but each {@link
49+
* feast.serving.ServingAPIProto.GetOnlineFeaturesRequest.EntityRow} must contain all entities for
50+
* all feature sets included in the request.
51+
*
52+
* <p>This request is fulfilled synchronously.
53+
*
54+
* @param getFeaturesRequest {@link GetOnlineFeaturesRequest} containing list of {@link
55+
* feast.serving.ServingAPIProto.FeatureReference}s to retrieve and list of {@link
56+
* feast.serving.ServingAPIProto.GetOnlineFeaturesRequest.EntityRow}s to join the retrieved
57+
* values to.
58+
* @return {@link GetOnlineFeaturesResponse} with list of {@link
59+
* feast.serving.ServingAPIProto.GetOnlineFeaturesResponse.FieldValues} for each {@link
60+
* feast.serving.ServingAPIProto.GetOnlineFeaturesRequest.EntityRow} supplied.
61+
*/
3262
GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequest getFeaturesRequest);
3363

64+
/**
65+
* Get features from a batch serving store, given a list of {@link
66+
* feast.serving.ServingAPIProto.FeatureReference}s to retrieve, and {@link
67+
* feast.serving.ServingAPIProto.DatasetSource} pointing to remote location of dataset to join
68+
* retrieved features to. All columns in the provided dataset will be preserved in the output
69+
* dataset.
70+
*
71+
* <p>Due to the potential size of batch retrieval requests, this request is fulfilled
72+
* asynchronously, and returns a retrieval job id, which when supplied to {@link
73+
* #getJob(GetJobRequest)} will return the status of the retrieval job.
74+
*
75+
* @param getFeaturesRequest {@link GetBatchFeaturesRequest} containing a list of {@link
76+
* feast.serving.ServingAPIProto.FeatureReference}s to retrieve, and {@link
77+
* feast.serving.ServingAPIProto.DatasetSource} pointing to remote location of dataset to join
78+
* retrieved features to.
79+
* @return {@link GetBatchFeaturesResponse} containing reference to a retrieval {@link
80+
* feast.serving.ServingAPIProto.Job}.
81+
*/
3482
GetBatchFeaturesResponse getBatchFeatures(GetBatchFeaturesRequest getFeaturesRequest);
3583

84+
/**
85+
* Get the status of a retrieval job from a batch serving store.
86+
*
87+
* <p>The client should check the status of the returned job periodically by calling ReloadJob to
88+
* determine if the job has completed successfully or with an error. If the job completes
89+
* successfully i.e. status = JOB_STATUS_DONE with no error, then the client can check the
90+
* file_uris for the location to download feature values data. The client is assumed to have
91+
* access to these file URIs.
92+
*
93+
* <p>If an error occurred during retrieval, the {@link GetJobResponse} will also contain the
94+
* error that resulted in termination.
95+
*
96+
* @param getJobRequest {@link GetJobRequest} containing reference to a retrieval job
97+
* @return {@link GetJobResponse}
98+
*/
3699
GetJobResponse getJob(GetJobRequest getJobRequest);
37100
}

storage/api/src/main/java/feast/storage/api/retrieval/HistoricalRetriever.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
*/
2626
public interface HistoricalRetriever {
2727

28+
/**
29+
* Get temporary staging location if applicable. If not applicable to this store, returns an empty
30+
* string.
31+
*
32+
* @return staging location uri
33+
*/
34+
String getStagingLocation();
35+
2836
/**
2937
* Get all features corresponding to the provided batch features request.
3038
*

storage/connectors/bigquery/src/main/java/feast/storage/connectors/bigquery/retrieval/BigQueryHistoricalRetriever.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public abstract static class Builder {
8585
public abstract BigQueryHistoricalRetriever build();
8686
}
8787

88+
@Override
89+
public String getStagingLocation() {
90+
return jobStagingLocation();
91+
}
92+
8893
@Override
8994
public HistoricalRetrievalResult getHistoricalFeatures(
9095
String retrievalId, DatasetSource datasetSource, List<FeatureSetRequest> featureSetRequests) {

0 commit comments

Comments
 (0)