Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug to unflatten the doc with list of map with multiple entries correctly #1204

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading