Skip to content

Commit

Permalink
change to iterator style and add unchecked SuppressWarnings
Browse files Browse the repository at this point in the history
Signed-off-by: wangdongyu.danny <[email protected]>
  • Loading branch information
wdongyu committed Oct 8, 2024
1 parent 7ce1115 commit de1a736
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -419,14 +420,12 @@ private void putNLPResultToSourceMapForMapType(
for (Map.Entry<String, Object> inputNestedMapEntry : ((Map<String, Object>) sourceValue).entrySet()) {
if (sourceAndMetadataMap.get(processorKey) instanceof List) {
// build nlp output for list of nested objects
List<Object> inputNestedMapValue = (List<Object>) inputNestedMapEntry.getValue();
int valueIndex = 0;
Iterator<Object> inputNestedMapValueIt = ((List<Object>) inputNestedMapEntry.getValue()).iterator();
for (Map<String, Object> nestedElement : (List<Map<String, Object>>) sourceAndMetadataMap.get(processorKey)) {
// Only fill in when value is not null
if (valueIndex < inputNestedMapValue.size() && inputNestedMapValue.get(valueIndex) != null) {
if (inputNestedMapValueIt.hasNext() && inputNestedMapValueIt.next() != null) {
nestedElement.put(inputNestedMapEntry.getKey(), results.get(indexWrapper.index++));
}
valueIndex++;
}
} else {
Pair<String, Object> processedNestedKey = processNestedKey(inputNestedMapEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ public void test_batchExecuteWithNull_allFailedValidation() {
assertEquals(docCount, captor.getValue().size());
for (int i = 0; i < docCount; ++i) {
assertNotNull(captor.getValue().get(i).getException());
assertEquals(
"list type field [key1] has null, cannot process it",
captor.getValue().get(i).getException().getMessage()
);
assertEquals("list type field [key1] has null, cannot process it", captor.getValue().get(i).getException().getMessage());
assertEquals(wrapperList.get(i).getIngestDocument(), captor.getValue().get(i).getIngestDocument());
}
verify(clientAccessor, never()).inferenceSentences(anyString(), anyList(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ public void testBuildVectorOutput_withNestedList_successful() {
assertNotNull(nestedObj.get(1).get("vectorField"));
}

@SuppressWarnings("unchecked")
public void testBuildVectorOutput_withNestedListHasNotForEmbeddingField_successful() {
Map<String, Object> config = createNestedListConfiguration();
IngestDocument ingestDocument = createNestedListWithNotEmbeddingFieldIngestDocument();
Expand Down Expand Up @@ -768,6 +769,7 @@ public void testBuildVectorOutput_withNestedList_Level2_successful() {
assertNotNull(nestedObj.get(1).get("vectorField"));
}

@SuppressWarnings("unchecked")
public void testBuildVectorOutput_withNestedListHasNotForEmbeddingField_Level2_successful() {
Map<String, Object> config = createNestedList2LevelConfiguration();
IngestDocument ingestDocument = create2LevelNestedListWithNotEmbeddingFieldIngestDocument();
Expand Down

0 comments on commit de1a736

Please sign in to comment.