-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add includeFields parameter to the method extractFieldNamesTypes (#376)…
… (#379) * Add includeFields parameter to the method extractFieldNamesTypes * Remove empty line --------- (cherry picked from commit 5a9dbcd) Signed-off-by: gaobinlong <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ae0d858
commit f3919d0
Showing
4 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/test/java/org/opensearch/agent/tools/ToolHelperTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.agent.tools; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
import org.opensearch.agent.tools.utils.ToolHelper; | ||
|
||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Log4j2 | ||
public class ToolHelperTests { | ||
@Test | ||
public void TestExtractFieldNamesTypes() { | ||
Map<String, Object> indexMappings = Map | ||
.of( | ||
"response", | ||
Map.of("type", "integer"), | ||
"responseLatency", | ||
Map.of("type", "float"), | ||
"date", | ||
Map.of("type", "date"), | ||
"objectA", | ||
Map.of("type", "object", "properties", Map.of("subA", Map.of("type", "keyword"))), | ||
"objectB", | ||
Map.of("properties", Map.of("subB", Map.of("type", "keyword"))), | ||
"textC", | ||
Map.of("type", "text", "fields", Map.of("subC", Map.of("type", "keyword"))), | ||
"aliasD", | ||
Map.of("type", "alias", "path", "date") | ||
); | ||
Map<String, String> result = new HashMap<>(); | ||
ToolHelper.extractFieldNamesTypes(indexMappings, result, "", true); | ||
assertMapEquals( | ||
result, | ||
Map | ||
.of( | ||
"response", | ||
"integer", | ||
"responseLatency", | ||
"float", | ||
"date", | ||
"date", | ||
"objectA.subA", | ||
"keyword", | ||
"objectB.subB", | ||
"keyword", | ||
"textC", | ||
"text", | ||
"textC.subC", | ||
"keyword" | ||
) | ||
); | ||
|
||
Map<String, String> result1 = new HashMap<>(); | ||
ToolHelper.extractFieldNamesTypes(indexMappings, result1, "", false); | ||
assertMapEquals( | ||
result1, | ||
Map | ||
.of( | ||
"response", | ||
"integer", | ||
"responseLatency", | ||
"float", | ||
"date", | ||
"date", | ||
"objectA.subA", | ||
"keyword", | ||
"objectB.subB", | ||
"keyword", | ||
"textC", | ||
"text" | ||
) | ||
); | ||
} | ||
|
||
private void assertMapEquals(Map<String, String> expected, Map<String, String> actual) { | ||
assertEquals(expected.size(), actual.size()); | ||
for (Map.Entry<String, String> entry : expected.entrySet()) { | ||
assertEquals(entry.getValue(), actual.get(entry.getKey())); | ||
} | ||
} | ||
} |