Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* fix name bug

* apply spotless

* change error message

---------

(cherry picked from commit 8074492)

Signed-off-by: xinyual <[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>
Signed-off-by: yuye-aws <[email protected]>
  • Loading branch information
2 people authored and yuye-aws committed Apr 26, 2024
1 parent caf1aa9 commit 74195b7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/org/opensearch/agent/tools/PPLTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
GetMappingsRequest getMappingsRequest = buildGetMappingRequest(indexName);
client.admin().indices().getMappings(getMappingsRequest, ActionListener.<GetMappingsResponse>wrap(getMappingsResponse -> {
Map<String, MappingMetadata> mappings = getMappingsResponse.getMappings();
if (mappings.size() == 0) {
throw new IllegalArgumentException("No matching mapping with index name: " + indexName);
}
client.search(searchRequest, ActionListener.<SearchResponse>wrap(searchResponse -> {
SearchHit[] searchHits = searchResponse.getHits().getHits();
String tableInfo = constructTableInfo(searchHits, mappings, indexName);
String tableInfo = constructTableInfo(searchHits, mappings);
String prompt = constructPrompt(tableInfo, question, indexName);
RemoteInferenceInputDataSet inputDataSet = RemoteInferenceInputDataSet
.builder()
Expand Down Expand Up @@ -286,9 +289,9 @@ private GetMappingsRequest buildGetMappingRequest(String indexName) {
return getMappingsRequest;
}

private String constructTableInfo(SearchHit[] searchHits, Map<String, MappingMetadata> mappings, String indexName)
throws PrivilegedActionException {
MappingMetadata mappingMetadata = mappings.get(indexName);
private String constructTableInfo(SearchHit[] searchHits, Map<String, MappingMetadata> mappings) throws PrivilegedActionException {
String firstIndexName = (String) mappings.keySet().toArray()[0];
MappingMetadata mappingMetadata = mappings.get(firstIndexName);
Map<String, Object> mappingSource = (Map<String, Object>) mappingMetadata.getSourceAsMap().get("properties");
Map<String, String> fieldsToType = new HashMap<>();
extractNamesTypes(mappingSource, fieldsToType, "");
Expand Down

0 comments on commit 74195b7

Please sign in to comment.