diff --git a/web/src/utils/query/sqlCompletion.spec.ts b/web/src/utils/query/sqlCompletion.spec.ts index ea36275a83..fc3b5d2e9c 100644 --- a/web/src/utils/query/sqlCompletion.spec.ts +++ b/web/src/utils/query/sqlCompletion.spec.ts @@ -849,6 +849,25 @@ describe("D1/N5 — field entries surface the column type", () => { expect(buildFieldEntry({ name: "code" } as any).detail).toBeUndefined(); }); + // Two field shapes exist in the app and both must work. Logs SCHEMA fields + // carry the type as `dataType` (useStreamFields.ts:452) while Logs DYNAMIC + // fields and the Alerts columns carry it as `type`. Reading only `type` left + // every schema field in Logs — the common case — with a blank detail, which + // 13k passing tests missed because every fixture used `type`. + it("reads the type from `dataType` as Logs schema fields supply it", () => { + expect(buildFieldEntry({ name: "host_name", dataType: "Utf8" } as any).detail).toBe("Utf8"); + }); + + it("still reads `type` as dynamic fields and Alerts columns supply it", () => { + expect(buildFieldEntry({ name: "code", type: "Int64" }).detail).toBe("Int64"); + }); + + it("prefers `type` when a field carries both", () => { + expect(buildFieldEntry({ name: "x", type: "Int64", dataType: "Utf8" } as any).detail).toBe( + "Int64", + ); + }); + it("does not mark a plain field name as a snippet", () => { expect(buildFieldEntry({ name: "code", type: "Utf8" }).insertTextRules).toBeUndefined(); }); diff --git a/web/src/utils/query/sqlCompletion.ts b/web/src/utils/query/sqlCompletion.ts index 942433fc9a..279be47b1f 100644 --- a/web/src/utils/query/sqlCompletion.ts +++ b/web/src/utils/query/sqlCompletion.ts @@ -981,7 +981,13 @@ export const buildFunctionArgs = (numArgs: number | string): string => { * discarded; it is exactly what belongs in the suggest widget's inline column, * and it is what type-aware operator suggestions will key off later. */ -export const buildFieldEntry = (field: { name: string; type?: string }): SqlCompletionEntry => { +export const buildFieldEntry = (field: { + name: string; + /** Dynamic fields and Alerts columns carry the type here. */ + type?: string; + /** Logs SCHEMA fields carry it here instead (useStreamFields.ts:452). */ + dataType?: string; +}): SqlCompletionEntry => { const entry: SqlCompletionEntry = { name: field.name, label: field.name, @@ -989,7 +995,9 @@ export const buildFieldEntry = (field: { name: string; type?: string }): SqlComp insertText: field.name, sortText: SORT_LANE.field + field.name, }; - // Omit rather than render "undefined" in the widget. - if (field.type) entry.detail = field.type; + // Two field shapes exist in the app: schema fields use `dataType`, dynamic + // fields and Alerts columns use `type`. Omit rather than render "undefined". + const columnType = field.type || field.dataType; + if (columnType) entry.detail = columnType; return entry; };