Skip to content

Commit

Permalink
fix name bug (opensearch-project#139)
Browse files Browse the repository at this point in the history
* fix name bug

Signed-off-by: xinyual <xinyual@amazon.com>

* apply spotless

Signed-off-by: xinyual <xinyual@amazon.com>

* change error message

Signed-off-by: xinyual <xinyual@amazon.com>

---------

Signed-off-by: xinyual <xinyual@amazon.com>
  • Loading branch information
xinyual authored Jan 23, 2024
1 parent 3e4d451 commit 8074492
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 @@ -149,9 +149,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 @@ -288,9 +291,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 8074492

Please sign in to comment.