Skip to content

Update ESQL helper types #2738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ export interface EsqlColumn {
type: string
}

export type EsqlValue = any[]

export type EsqlRow = EsqlValue[]

export interface EsqlResponse {
columns: EsqlColumn[]
values: EsqlRow[]
}

export interface EsqlHelper {
toRecords: <TDocument>() => Promise<EsqlToRecords<TDocument>>
toArrowTable: () => Promise<Table<TypeMap>>
Expand Down Expand Up @@ -963,7 +954,7 @@ export default class Helpers {
esql (params: T.EsqlQueryRequest, reqOptions: TransportRequestOptions = {}): EsqlHelper {
const client = this[kClient]

function toRecords<TDocument> (response: EsqlResponse): TDocument[] {
function toRecords<TDocument> (response: T.EsqlEsqlResult): TDocument[] {
const { columns, values } = response
return values.map(row => {
const doc: Partial<TDocument> = {}
Expand All @@ -990,8 +981,7 @@ export default class Helpers {

params.format = 'json'
params.columnar = false
// @ts-expect-error it's typed as ArrayBuffer but we know it will be JSON
const response: EsqlResponse = await client.esql.query(params, reqOptions)
const response = await client.esql.query(params, reqOptions)
const records: TDocument[] = toRecords(response)
const { columns } = response
return { records, columns }
Expand All @@ -1005,7 +995,8 @@ export default class Helpers {

params.format = 'arrow'

const response = await client.esql.query(params, reqOptions)
// @ts-expect-error the return type will be ArrayBuffer when the format is set to 'arrow'
const response: ArrayBuffer = await client.esql.query(params, reqOptions)
return tableFromIPC(response)
},

Expand All @@ -1018,7 +1009,8 @@ export default class Helpers {

params.format = 'arrow'

const response = await client.esql.query(params, reqOptions)
// @ts-expect-error the return type will be ArrayBuffer when the format is set to 'arrow'
const response: ArrayBuffer = await client.esql.query(params, reqOptions)
return RecordBatchStreamReader.from(response)
}
}
Expand Down
Loading