Skip to content

Commit 072f894

Browse files
authoredDec 20, 2024··
fix(FIR-38127): special case for struct (#128)
1 parent 62ed49c commit 072f894

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎src/statement/dataTypes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ const trimElement = (element: string) =>
105105
const decomposeSingleStructType = (type: string): [string, string] => {
106106
// Given a single struct element like "a int", extract the field and type
107107
// Finds the second backtick if any or the first space to separate field and type
108-
let index = type.indexOf("`", 1);
108+
let index = type.startsWith("`") ? type.indexOf("`", 1) : -1;
109+
// If current type is not a quoted field, find the first space
109110
if (index === -1) {
110111
index = type.indexOf(" ");
111112
}

‎test/unit/v2/statement.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,24 @@ describe("parse values", () => {
351351
const res: Record<string, Record<string, any>> = hydrateRow(row, meta, {});
352352
expect(res["s"]).toEqual({ a: [1, null], b: { c: null } });
353353
});
354+
it("parses nested struct with single struct correctly", () => {
355+
const row = {
356+
s: { a: { "c d": null } }
357+
};
358+
const meta = [{ name: "s", type: "struct(a struct(`c d` text null))" }];
359+
const res: Record<string, Record<string, any>> = hydrateRow(row, meta, {});
360+
expect(res["s"]).toEqual({ a: { "c d": null } });
361+
});
362+
it("parses nested struct with single struct mixed quoting", () => {
363+
const row = {
364+
s: { a: { e: "test", "c d": null } }
365+
};
366+
const meta = [
367+
{ name: "s", type: "struct(a struct(e text,`c d` text null))" }
368+
];
369+
const res: Record<string, Record<string, any>> = hydrateRow(row, meta, {});
370+
expect(res["s"]).toEqual({ a: { e: "test", "c d": null } });
371+
});
354372
it("does not break on malformed struct", () => {
355373
const row = {
356374
s: { a: [1, 2], b: "hello" }

0 commit comments

Comments
 (0)
Please sign in to comment.