( result: QueryResult )
| 422 | * search response. |
| 423 | */ |
| 424 | export const flattenElasticsearchSearchResult = ( |
| 425 | result: QueryResult |
| 426 | ): QueryResult | undefined => { |
| 427 | const hitsArray = parseESHitsArray(result); |
| 428 | if (!hitsArray) return undefined; |
| 429 | |
| 430 | const { metaFields, allColumns, columnIndexMap } = |
| 431 | discoverESColumns(hitsArray); |
| 432 | const columnTypeNames: string[] = Array.from({ |
| 433 | length: allColumns.length, |
| 434 | }).map(() => "TEXT"); |
| 435 | |
| 436 | const rows = hitsArray.map((hit) => |
| 437 | buildESHitRow( |
| 438 | hit as Record<string, unknown>, |
| 439 | metaFields, |
| 440 | allColumns.length, |
| 441 | columnIndexMap, |
| 442 | columnTypeNames |
| 443 | ) |
| 444 | ); |
| 445 | |
| 446 | return createProto(QueryResultSchema, { |
| 447 | columnNames: allColumns, |
| 448 | columnTypeNames, |
| 449 | rows, |
| 450 | rowsCount: BigInt(rows.length), |
| 451 | statement: result.statement, |
| 452 | latency: result.latency, |
| 453 | }); |
| 454 | }; |
| 455 | |
| 456 | const getNoSQLColumns = (rows: QueryRow[]) => { |
| 457 | const columnSet = new Set<string>(); |
no test coverage detected