( hit: Record<string, unknown>, metaFields: string[], columnCount: number, columnIndexMap: Map<string, number>, columnTypeNames: string[] )
| 376 | |
| 377 | // Builds a single QueryRow from an ES hit document. |
| 378 | const buildESHitRow = ( |
| 379 | hit: Record<string, unknown>, |
| 380 | metaFields: string[], |
| 381 | columnCount: number, |
| 382 | columnIndexMap: Map<string, number>, |
| 383 | columnTypeNames: string[] |
| 384 | ): QueryRow => { |
| 385 | const values: RowValue[] = Array.from({ length: columnCount }).map(() => |
| 386 | createProto(RowValueSchema, { |
| 387 | kind: { case: "nullValue", value: NullValue.NULL_VALUE }, |
| 388 | }) |
| 389 | ); |
| 390 | |
| 391 | for (const field of metaFields) { |
| 392 | const idx = columnIndexMap.get(field); |
| 393 | if (idx === undefined) continue; |
| 394 | const val = hit[field]; |
| 395 | if (val != null) { |
| 396 | const { value: formatted, type } = convertAnyToRowValue(val, false); |
| 397 | values[idx] = formatted; |
| 398 | columnTypeNames[idx] = type; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | const source = hit._source; |
| 403 | if (source && typeof source === "object") { |
| 404 | for (const [key, val] of Object.entries(source)) { |
| 405 | const idx = columnIndexMap.get(key); |
| 406 | if (idx === undefined) continue; |
| 407 | if (val != null) { |
| 408 | const { value: formatted, type } = convertAnyToRowValue(val, true); |
| 409 | values[idx] = formatted; |
| 410 | columnTypeNames[idx] = type; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | return createProto(QueryRowSchema, { values }); |
| 416 | }; |
| 417 | |
| 418 | /** |
| 419 | * Transforms an Elasticsearch _search QueryResult into a tabular format. |
no test coverage detected