|
70 | 70 | import org.apache.arrow.vector.types.pojo.Field; |
71 | 71 | import org.apache.arrow.vector.types.pojo.Schema; |
72 | 72 | import org.apache.arrow.vector.util.ByteArrayReadableSeekableByteChannel; |
| 73 | +import org.apache.commons.lang3.tuple.ImmutablePair; |
73 | 74 | import org.apache.commons.lang3.tuple.Pair; |
74 | 75 | import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream; |
75 | 76 | import org.slf4j.Logger; |
@@ -120,45 +121,11 @@ public GetOnlineFeaturesResponse getOnlineFeatures(GetOnlineFeaturesRequestV2 re |
120 | 121 |
|
121 | 122 | // Get the set of request data feature names from the ODFV references. |
122 | 123 | // 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(); |
162 | 129 |
|
163 | 130 | // Add on demand feature inputs to list of feature references to retrieve. |
164 | 131 | Set<FeatureReferenceV2> addedFeatureReferences = new HashSet<FeatureReferenceV2>(); |
@@ -514,6 +481,64 @@ private void populateFeatureCountMetrics( |
514 | 481 | .inc()); |
515 | 482 | } |
516 | 483 |
|
| 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 | + |
517 | 542 | /** |
518 | 543 | * Process a response from the feature transformation server by augmenting the given lists of |
519 | 544 | * field maps and status maps with the correct fields from the response. |
|
0 commit comments