fix(editor): read the column type from dataType as well as type

Found by running the app, not by the suite: every field in Logs showed a blank
type in the suggest widget.

Two field shapes exist and buildFieldEntry only handled one. Logs SCHEMA fields
-- the common case -- carry the column type as `dataType`
(useStreamFields.ts:452), while Logs DYNAMIC fields and the Alerts columns carry
it as `type`. 13k passing tests missed this because every fixture I wrote used
`type`, which is exactly the shape the code already handled.

Verified live: host_name, status_code and severity now show Utf8.
This commit is contained in:
Prabhat Sharma 2026-08-02 13:41:41 -07:00
parent 75ba683ef4
commit be930e234a
2 changed files with 30 additions and 3 deletions

View File

@ -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();
});

View File

@ -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;
};