Skip to content

Commit d98a80d

Browse files
committed
More refactors
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
1 parent 2a6f093 commit d98a80d

File tree

1 file changed

+64
-39
lines changed

1 file changed

+64
-39
lines changed

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

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.apache.arrow.vector.types.pojo.Field;
7171
import org.apache.arrow.vector.types.pojo.Schema;
7272
import org.apache.arrow.vector.util.ByteArrayReadableSeekableByteChannel;
73+
import org.apache.commons.lang3.tuple.ImmutablePair;
7374
import org.apache.commons.lang3.tuple.Pair;
7475
import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream;
7576
import org.slf4j.Logger;
@@ -120,45 +121,11 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequestV2 re
120121

121122
// Get the set of request data feature names from the ODFV references.
122123
// Also get the batch feature view references that the ODFVs require as inputs.
123-
Pair<Set<String>, List<FeatureReferenceV2>> pair;
124-
Set<String> requestDataFeatureNames = new HashSet<String>();
125-
List<FeatureReferenceV2> onDemandFeatureInputs = new ArrayList<FeatureReferenceV2>();
126-
for (FeatureReferenceV2 featureReference : onDemandFeatureReferences) {
127-
OnDemandFeatureViewSpec onDemandFeatureViewSpec =
128-
this.featureSpecRetriever.getOnDemandFeatureViewSpec(projectName, featureReference);
129-
Map<String, OnDemandInput> inputs = onDemandFeatureViewSpec.getInputsMap();
130-
131-
for (OnDemandInput input : inputs.values()) {
132-
OnDemandInput.InputCase inputCase = input.getInputCase();
133-
switch (inputCase) {
134-
case REQUEST_DATA_SOURCE:
135-
DataSource requestDataSource = input.getRequestDataSource();
136-
RequestDataOptions requestDataOptions = requestDataSource.getRequestDataOptions();
137-
Set<String> requestDataNames = requestDataOptions.getSchemaMap().keySet();
138-
requestDataFeatureNames.addAll(requestDataNames);
139-
break;
140-
case FEATURE_VIEW:
141-
FeatureView featureView = input.getFeatureView();
142-
FeatureViewSpec featureViewSpec = featureView.getSpec();
143-
String featureViewName = featureViewSpec.getName();
144-
for (FeatureSpecV2 featureSpec : featureViewSpec.getFeaturesList()) {
145-
String featureName = featureSpec.getName();
146-
FeatureReferenceV2 onDemandFeatureInput =
147-
FeatureReferenceV2.newBuilder()
148-
.setFeatureTable(featureViewName)
149-
.setName(featureName)
150-
.build();
151-
onDemandFeatureInputs.add(onDemandFeatureInput);
152-
}
153-
break;
154-
default:
155-
throw Status.INTERNAL
156-
.withDescription(
157-
"OnDemandInput proto input field has an unexpected type: " + inputCase)
158-
.asRuntimeException();
159-
}
160-
}
161-
}
124+
Pair<Set<String>, List<FeatureReferenceV2>> pair =
125+
extractRequestDataFeatureNamesAndOnDemandFeatureInputs(
126+
onDemandFeatureReferences, projectName);
127+
Set<String> requestDataFeatureNames = pair.getLeft();
128+
List<FeatureReferenceV2> onDemandFeatureInputs = pair.getRight();
162129

163130
// Add on demand feature inputs to list of feature references to retrieve.
164131
Set<FeatureReferenceV2> addedFeatureReferences = new HashSet<FeatureReferenceV2>();
@@ -514,6 +481,64 @@ private void populateFeatureCountMetrics(
514481
.inc());
515482
}
516483

484+
/**
485+
* Extract the set of request data feature names and the list of on demand feature inputs from a
486+
* list of ODFV references.
487+
*
488+
* @param onDemandFeatureReferences list of ODFV references to be parsed
489+
* @param projectName project name
490+
* @return a pair containing the set of request data feature names and list of on demand feature
491+
* inputs
492+
*/
493+
private Pair<Set<String>, List<FeatureReferenceV2>>
494+
extractRequestDataFeatureNamesAndOnDemandFeatureInputs(
495+
List<FeatureReferenceV2> onDemandFeatureReferences, String projectName) {
496+
// Get the set of request data feature names from the ODFV references.
497+
// Also get the batch feature view references that the ODFVs require as inputs.
498+
Set<String> requestDataFeatureNames = new HashSet<String>();
499+
List<FeatureReferenceV2> onDemandFeatureInputs = new ArrayList<FeatureReferenceV2>();
500+
for (FeatureReferenceV2 featureReference : onDemandFeatureReferences) {
501+
OnDemandFeatureViewSpec onDemandFeatureViewSpec =
502+
this.featureSpecRetriever.getOnDemandFeatureViewSpec(projectName, featureReference);
503+
Map<String, OnDemandInput> inputs = onDemandFeatureViewSpec.getInputsMap();
504+
505+
for (OnDemandInput input : inputs.values()) {
506+
OnDemandInput.InputCase inputCase = input.getInputCase();
507+
switch (inputCase) {
508+
case REQUEST_DATA_SOURCE:
509+
DataSource requestDataSource = input.getRequestDataSource();
510+
RequestDataOptions requestDataOptions = requestDataSource.getRequestDataOptions();
511+
Set<String> requestDataNames = requestDataOptions.getSchemaMap().keySet();
512+
requestDataFeatureNames.addAll(requestDataNames);
513+
break;
514+
case FEATURE_VIEW:
515+
FeatureView featureView = input.getFeatureView();
516+
FeatureViewSpec featureViewSpec = featureView.getSpec();
517+
String featureViewName = featureViewSpec.getName();
518+
for (FeatureSpecV2 featureSpec : featureViewSpec.getFeaturesList()) {
519+
String featureName = featureSpec.getName();
520+
FeatureReferenceV2 onDemandFeatureInput =
521+
FeatureReferenceV2.newBuilder()
522+
.setFeatureTable(featureViewName)
523+
.setName(featureName)
524+
.build();
525+
onDemandFeatureInputs.add(onDemandFeatureInput);
526+
}
527+
break;
528+
default:
529+
throw Status.INTERNAL
530+
.withDescription(
531+
"OnDemandInput proto input field has an unexpected type: " + inputCase)
532+
.asRuntimeException();
533+
}
534+
}
535+
}
536+
Pair<Set<String>, List<FeatureReferenceV2>> pair =
537+
new ImmutablePair<Set<String>, List<FeatureReferenceV2>>(
538+
requestDataFeatureNames, onDemandFeatureInputs);
539+
return pair;
540+
}
541+
517542
/**
518543
* Process a response from the feature transformation server by augmenting the given lists of
519544
* field maps and status maps with the correct fields from the response.

0 commit comments

Comments
 (0)