fix(node): validate inferred types across records

This commit is contained in:
Gatefixer
2026-08-05 17:56:39 +00:00
parent c7ea91f3ea
commit 6ce4f84271
2 changed files with 17 additions and 4 deletions
+12
View File
@@ -449,6 +449,18 @@ describe.each([arrow15, arrow16, arrow17, arrow18])(
);
});
it("will allow matching inferred types across records", function () {
expect(() =>
makeArrowTable([{ value: 1 }, { value: 2 }]),
).not.toThrow();
});
it("will reject mismatched inferred types across records", function () {
expect(() => makeArrowTable([{ value: 1 }, { value: "two" }])).toThrow(
"Failed to infer schema for data. Previously inferred type Float64 but found Utf8 at row 1. Consider providing an explicit schema.",
);
});
it("will allow a schema to be provided", async function () {
await checkTableCreation(
async (records, _, schema) =>
+5 -4
View File
@@ -489,10 +489,11 @@ function inferSchema(
} else if (schema === undefined) {
const currentType = pathTree.get(path);
const newType = inferType(value, path, opts);
if (currentType !== newType) {
new Error(`Failed to infer schema for data. Previously inferred type \
${currentType} but found ${newType} at row ${rowI}. Consider \
providing an explicit schema.`);
if (currentType?.toString() !== newType?.toString()) {
throw new Error(
`Failed to infer schema for data. Previously inferred type ${currentType} ` +
`but found ${newType} at row ${rowI}. Consider providing an explicit schema.`,
);
}
}
}