Skip to content

Commit f671c20

Browse files
bzhangamgithub-actions[bot]
authored andcommitted
Fix a bug to unflatten the doc with list of map with multiple entries correctly. (#1204)
Signed-off-by: Bo Zhang <bzhangam@amazon.com> (cherry picked from commit da5eebb)
1 parent 5ea6d30 commit f671c20

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
### Features
88
### Enhancements
99
### Bug Fixes
10+
- 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)).
1011
### Infrastructure
1112
### Documentation
1213
### Maintenance

src/main/java/org/opensearch/neuralsearch/util/ProcessorDocumentUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private static List<Object> handleList(List<Object> list) {
263263
ProcessJsonObjectItem processJsonObjectItem = (ProcessJsonObjectItem) value;
264264
Map<String, Object> tempMap = new HashMap<>();
265265
unflattenSingleItem(processJsonObjectItem.key, processJsonObjectItem.value, tempMap);
266-
targetList.set(targetList.size() - 1, tempMap);
266+
processJsonObjectItem.targetMap.putAll(tempMap);
267267
} else {
268268
targetList.add(value);
269269
}

src/test/java/org/opensearch/neuralsearch/util/ProcessorDocumentUtilsTests.java

+19
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ public void testUnflatten_withList_thenSuccess() {
134134
assertEquals(expected, result);
135135
}
136136

137+
public void testUnflatten_withListOfObject_thenSuccess() {
138+
Map<String, Object> map1 = Map.of("b.c", "d", "f", "h");
139+
Map<String, Object> map2 = Map.of("b.c", "e", "f", "i");
140+
List<Map<String, Object>> list = Arrays.asList(map1, map2);
141+
Map<String, Object> input = Map.of("a", list);
142+
143+
Map<String, Object> nestedB1 = Map.of("c", "d");
144+
Map<String, Object> expectedMap1 = Map.of("b", nestedB1, "f", "h");
145+
Map<String, Object> nestedB2 = Map.of("c", "e");
146+
Map<String, Object> expectedMap2 = Map.of("b", nestedB2, "f", "i");
147+
148+
List<Map<String, Object>> expectedList = Arrays.asList(expectedMap1, expectedMap2);
149+
150+
Map<String, Object> expected = Map.of("a", expectedList);
151+
152+
Map<String, Object> result = ProcessorDocumentUtils.unflattenJson(input);
153+
assertEquals(expected, result);
154+
}
155+
137156
public void testUnflatten_withMixedContent_thenSuccess() {
138157
Map<String, Object> input = Map.of("a.b", "c", "d", "e", "f.g.h", "i");
139158

0 commit comments

Comments
 (0)