Skip to content

Commit

Permalink
Fix a bug to unflatten the doc with list of map with multiple entries…
Browse files Browse the repository at this point in the history
… correctly. (#1204)

Signed-off-by: Bo Zhang <bzhangam@amazon.com>
  • Loading branch information
bzhangam authored Feb 28, 2025
1 parent 9cc8959 commit da5eebb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Set neural-search plugin 3.0.0 baseline JDK version to JDK-21 ([#838](https://github.com/opensearch-project/neural-search/pull/838))
- Support different embedding types in model's response ([#1007](https://github.com/opensearch-project/neural-search/pull/1007))
### Bug Fixes
- Fix a bug to unflatten the doc with list of map with multiple entries correctly ([#1204](https://github.com/opensearch-project/neural-search/pull/1204)).
### Infrastructure
- [3.0] Update neural-search for OpenSearch 3.0 compatibility ([#1141](https://github.com/opensearch-project/neural-search/pull/1141))
### Documentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private static List<Object> handleList(List<Object> list) {
ProcessJsonObjectItem processJsonObjectItem = (ProcessJsonObjectItem) value;
Map<String, Object> tempMap = new HashMap<>();
unflattenSingleItem(processJsonObjectItem.key, processJsonObjectItem.value, tempMap);
targetList.set(targetList.size() - 1, tempMap);
processJsonObjectItem.targetMap.putAll(tempMap);
} else {
targetList.add(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ public void testUnflatten_withList_thenSuccess() {
assertEquals(expected, result);
}

public void testUnflatten_withListOfObject_thenSuccess() {
Map<String, Object> map1 = Map.of("b.c", "d", "f", "h");
Map<String, Object> map2 = Map.of("b.c", "e", "f", "i");
List<Map<String, Object>> list = Arrays.asList(map1, map2);
Map<String, Object> input = Map.of("a", list);

Map<String, Object> nestedB1 = Map.of("c", "d");
Map<String, Object> expectedMap1 = Map.of("b", nestedB1, "f", "h");
Map<String, Object> nestedB2 = Map.of("c", "e");
Map<String, Object> expectedMap2 = Map.of("b", nestedB2, "f", "i");

List<Map<String, Object>> expectedList = Arrays.asList(expectedMap1, expectedMap2);

Map<String, Object> expected = Map.of("a", expectedList);

Map<String, Object> result = ProcessorDocumentUtils.unflattenJson(input);
assertEquals(expected, result);
}

public void testUnflatten_withMixedContent_thenSuccess() {
Map<String, Object> input = Map.of("a.b", "c", "d", "e", "f.g.h", "i");

Expand Down

0 comments on commit da5eebb

Please sign in to comment.