MCPcopy Create free account
hub / github.com/bytebase/bytebase / discoverESColumns

Function discoverESColumns

frontend/src/utils/sqlResult.ts:355–375  ·  view source on GitHub ↗
(hitsArray: unknown[])

Source from the content-addressed store, hash-verified

353
354// Discovers columns from ES hits: _id, _score, then sorted _source field keys.
355const discoverESColumns = (hitsArray: unknown[]) => {
356 const metaFields = ["_id", "_score"];
357 const sourceKeySet = new Set<string>();
358 for (const hit of hitsArray) {
359 const source = (hit as Record<string, unknown>)?._source;
360 if (source && typeof source === "object") {
361 for (const key of Object.keys(source)) {
362 sourceKeySet.add(key);
363 }
364 }
365 }
366 const allColumns = [
367 ...metaFields,
368 ...[...sourceKeySet].sort((a, b) => a.localeCompare(b)),
369 ];
370 const columnIndexMap = new Map<string, number>();
371 for (let i = 0; i < allColumns.length; i++) {
372 columnIndexMap.set(allColumns[i], i);
373 }
374 return { metaFields, allColumns, columnIndexMap };
375};
376
377// Builds a single QueryRow from an ES hit document.
378const buildESHitRow = (

Callers 1

Calls 3

keysMethod · 0.80
addMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected