-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES|QL] Fetch the query columns utils (#181969)
## Summary Adds a new utility for the users who want to retrieve the columns from a query without expressions but using the search strategy. This is the first utility to add for fetching ES|QL data without expressions. This is only for columns but we can extend for fetching the entire table instead. The latter will be part of #179641 (comment) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
465daa7
commit 4262afe
Showing
8 changed files
with
107 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import type { DatatableColumn } from '@kbn/expressions-plugin/common'; | ||
import type { ISearchStart } from '@kbn/data-plugin/public'; | ||
import { esFieldTypeToKibanaFieldType } from '@kbn/field-types'; | ||
import type { ESQLSearchReponse } from '@kbn/es-types'; | ||
import { lastValueFrom } from 'rxjs'; | ||
import { ESQL_LATEST_VERSION } from '../../constants'; | ||
|
||
export async function getESQLQueryColumns({ | ||
esqlQuery, | ||
search, | ||
signal, | ||
}: { | ||
esqlQuery: string; | ||
search: ISearchStart; | ||
signal?: AbortSignal; | ||
}): Promise<DatatableColumn[]> { | ||
const response = await lastValueFrom( | ||
search.search( | ||
{ | ||
params: { | ||
query: `${esqlQuery} | limit 0`, | ||
version: ESQL_LATEST_VERSION, | ||
}, | ||
}, | ||
{ | ||
abortSignal: signal, | ||
strategy: 'esql_async', | ||
} | ||
) | ||
); | ||
|
||
const columns = | ||
(response.rawResponse as unknown as ESQLSearchReponse).columns?.map(({ name, type }) => { | ||
const kibanaType = esFieldTypeToKibanaFieldType(type); | ||
const column = { | ||
id: name, | ||
name, | ||
meta: { type: kibanaType, esType: type }, | ||
} as DatatableColumn; | ||
|
||
return column; | ||
}) ?? []; | ||
|
||
return columns; | ||
} |
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
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