Skip to content

Commit

Permalink
No need for a PreviewRow
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Jan 16, 2025
1 parent 6be2755 commit b97136a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public TransportPreviewDataFrameAnalyticsAction(
this.clusterService = clusterService;
}

private static Map<String, Object> mergeRow(DataFrameDataExtractor.PreviewRow row, List<String> fieldNames) {
return row.getValues() == null
private static Map<String, Object> mergeRow(String[] row, List<String> fieldNames) {
return row == null
? Collections.emptyMap()
: IntStream.range(0, row.getValues().length).boxed().collect(Collectors.toMap(fieldNames::get, i -> row.getValues()[i]));
: IntStream.range(0, row.length).boxed().collect(Collectors.toMap(fieldNames::get, i -> row[i]));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Optional<SearchHit[]> next() throws IOException {
* Does no sorting of the results.
* @param listener To alert with the extracted rows
*/
public void preview(ActionListener<List<PreviewRow>> listener) {
public void preview(ActionListener<List<String[]>> listener) {

SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client)
// This ensures the search throws if there are failures and the scroll context gets cleared automatically
Expand Down Expand Up @@ -154,10 +154,10 @@ public void preview(ActionListener<List<PreviewRow>> listener) {
return;
}

List<PreviewRow> rows = new ArrayList<>(searchResponse.getHits().getHits().length);
List<String[]> rows = new ArrayList<>(searchResponse.getHits().getHits().length);
for (SearchHit hit : searchResponse.getHits().getHits()) {
String[] extractedValues = extractValues(hit);
rows.add(new PreviewRow(extractedValues));
rows.add(extractedValues);
}
delegate.onResponse(rows);
})
Expand Down Expand Up @@ -433,21 +433,6 @@ public DataSummary(long rows, int cols) {
}
}

public static class PreviewRow {

@Nullable
private final String[] values;

private PreviewRow(String[] values) {
this.values = values;
}

@Nullable
public String[] getValues() {
return values;
}
}

public static class Row {

private final SearchHit hit;
Expand Down

0 comments on commit b97136a

Please sign in to comment.