@@ -119,8 +119,7 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequestV2 re
119119 .filter (r -> this .featureSpecRetriever .isOnDemandFeatureReference (r ))
120120 .collect (Collectors .toList ());
121121
122- // Get the set of request data feature names from the ODFV references.
123- // Also get the batch feature view references that the ODFVs require as inputs.
122+ // Get the set of request data feature names and feature inputs from the ODFV references.
124123 Pair <Set <String >, List <FeatureReferenceV2 >> pair =
125124 extractRequestDataFeatureNamesAndOnDemandFeatureInputs (
126125 onDemandFeatureReferences , projectName );
@@ -137,38 +136,12 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequestV2 re
137136 }
138137
139138 // Separate entity rows into entity data and request feature data.
139+ Pair <List <GetOnlineFeaturesRequestV2 .EntityRow >, Map <String , List <ValueProto .Value >>>
140+ entityRowsAndRequestDataFeatures = separateEntityRows (requestDataFeatureNames , request );
140141 List <GetOnlineFeaturesRequestV2 .EntityRow > entityRows =
141- new ArrayList < GetOnlineFeaturesRequestV2 . EntityRow > ();
142+ entityRowsAndRequestDataFeatures . getLeft ();
142143 Map <String , List <ValueProto .Value >> requestDataFeatures =
143- new HashMap <String , List <ValueProto .Value >>();
144-
145- for (GetOnlineFeaturesRequestV2 .EntityRow entityRow : request .getEntityRowsList ()) {
146- Map <String , ValueProto .Value > fieldsMap = new HashMap <String , ValueProto .Value >();
147-
148- for (Map .Entry <String , ValueProto .Value > entry : entityRow .getFieldsMap ().entrySet ()) {
149- String key = entry .getKey ();
150- ValueProto .Value value = entry .getValue ();
151-
152- if (requestDataFeatureNames .contains (key )) {
153- if (!requestDataFeatures .containsKey (key )) {
154- requestDataFeatures .put (key , new ArrayList <ValueProto .Value >());
155- }
156- requestDataFeatures .get (key ).add (value );
157- } else {
158- fieldsMap .put (key , value );
159- }
160- }
161-
162- // Construct new entity row containing the extracted entity data, if necessary.
163- if (!fieldsMap .isEmpty ()) {
164- GetOnlineFeaturesRequestV2 .EntityRow newEntityRow =
165- GetOnlineFeaturesRequestV2 .EntityRow .newBuilder ()
166- .setTimestamp (entityRow .getTimestamp ())
167- .putAllFields (fieldsMap )
168- .build ();
169- entityRows .add (newEntityRow );
170- }
171- }
144+ entityRowsAndRequestDataFeatures .getRight ();
172145 // TODO: error checking on lengths of lists in entityRows and requestDataFeatures
173146
174147 // Extract values and statuses to be used later in constructing FieldValues for the response.
@@ -493,8 +466,6 @@ private void populateFeatureCountMetrics(
493466 private Pair <Set <String >, List <FeatureReferenceV2 >>
494467 extractRequestDataFeatureNamesAndOnDemandFeatureInputs (
495468 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.
498469 Set <String > requestDataFeatureNames = new HashSet <String >();
499470 List <FeatureReferenceV2 > onDemandFeatureInputs = new ArrayList <FeatureReferenceV2 >();
500471 for (FeatureReferenceV2 featureReference : onDemandFeatureReferences ) {
@@ -539,6 +510,57 @@ private void populateFeatureCountMetrics(
539510 return pair ;
540511 }
541512
513+ /**
514+ * Separate the entity rows of a request into entity data and request feature data.
515+ *
516+ * @param requestDataFeatureNames set of feature names for the request data
517+ * @param request the GetOnlineFeaturesRequestV2 containing the entity rows
518+ * @return a pair containing the set of request data feature names and list of on demand feature
519+ * inputs
520+ */
521+ private Pair <List <GetOnlineFeaturesRequestV2 .EntityRow >, Map <String , List <ValueProto .Value >>>
522+ separateEntityRows (Set <String > requestDataFeatureNames , GetOnlineFeaturesRequestV2 request ) {
523+ // Separate entity rows into entity data and request feature data.
524+ List <GetOnlineFeaturesRequestV2 .EntityRow > entityRows =
525+ new ArrayList <GetOnlineFeaturesRequestV2 .EntityRow >();
526+ Map <String , List <ValueProto .Value >> requestDataFeatures =
527+ new HashMap <String , List <ValueProto .Value >>();
528+
529+ for (GetOnlineFeaturesRequestV2 .EntityRow entityRow : request .getEntityRowsList ()) {
530+ Map <String , ValueProto .Value > fieldsMap = new HashMap <String , ValueProto .Value >();
531+
532+ for (Map .Entry <String , ValueProto .Value > entry : entityRow .getFieldsMap ().entrySet ()) {
533+ String key = entry .getKey ();
534+ ValueProto .Value value = entry .getValue ();
535+
536+ if (requestDataFeatureNames .contains (key )) {
537+ if (!requestDataFeatures .containsKey (key )) {
538+ requestDataFeatures .put (key , new ArrayList <ValueProto .Value >());
539+ }
540+ requestDataFeatures .get (key ).add (value );
541+ } else {
542+ fieldsMap .put (key , value );
543+ }
544+ }
545+
546+ // Construct new entity row containing the extracted entity data, if necessary.
547+ if (!fieldsMap .isEmpty ()) {
548+ GetOnlineFeaturesRequestV2 .EntityRow newEntityRow =
549+ GetOnlineFeaturesRequestV2 .EntityRow .newBuilder ()
550+ .setTimestamp (entityRow .getTimestamp ())
551+ .putAllFields (fieldsMap )
552+ .build ();
553+ entityRows .add (newEntityRow );
554+ }
555+ }
556+
557+ Pair <List <GetOnlineFeaturesRequestV2 .EntityRow >, Map <String , List <ValueProto .Value >>> pair =
558+ new ImmutablePair <
559+ List <GetOnlineFeaturesRequestV2 .EntityRow >, Map <String , List <ValueProto .Value >>>(
560+ entityRows , requestDataFeatures );
561+ return pair ;
562+ }
563+
542564 /**
543565 * Process a response from the feature transformation server by augmenting the given lists of
544566 * field maps and status maps with the correct fields from the response.
0 commit comments