Skip to content

Commit 19b2159

Browse files
authored
Bug fix: correct the column when SELECT function as field (#462)
1 parent ede36f2 commit 19b2159

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/java/com/amazon/opendistroforelasticsearch/sql/executor/csv/CSVResultsExtractor.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ private List<String> createHeadersAndFillDocsMap(final boolean flat, final Searc
310310
doc.put("_type", hit.getType());
311311
}
312312

313-
mergeHeaders(csvHeaders, doc, flat);
313+
// select function as field is a special case where each hit has non-null field (function)
314+
// and sourceAsMap is all columns in index (the same as 'SELECT *')
315+
if (fields.isEmpty()) {
316+
mergeHeaders(csvHeaders, doc, flat);
317+
}
314318
docsAsMap.add(doc);
315319
}
316320

src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/CsvFormatResponseIT.java

+8
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,14 @@ public void sensitiveCharacterSanitizeAndQuotedTest() throws IOException {
660660
Assert.assertTrue(lines.get(0).contains("\",,,@cmd|' /C notepad'!_xlbgnm.A1\""));
661661
}
662662

663+
@Test
664+
public void selectFunctionAsFieldTest() throws IOException {
665+
String query = "select log(age) from " + TEST_INDEX_ACCOUNT;
666+
CSVResult result = executeCsvRequest(query, false, false, false, false);
667+
List<String> headers = result.getHeaders();
668+
Assert.assertEquals(1, headers.size());
669+
}
670+
663671
private void verifyFieldOrder(final String[] expectedFields) throws IOException {
664672

665673
final String fields = String.join(", ", expectedFields);

0 commit comments

Comments
 (0)