fix: count non-BMP characters once when naming a default table in the canvas and cli

This commit is contained in:
Ruben Fiszel
2026-11-03 04:07:08 +01:00
parent ee17d9847a
commit 13c3701631
5 changed files with 14 additions and 2 deletions
@@ -2787,6 +2787,12 @@ mod pipeline_annotation_tests {
.materialize
.unwrap();
assert_eq!(m.target_path, "main/_2026_orders");
// One `_` per character, as the TS and CLI mirrors count them, whatever its width.
let m = parse_pipeline_annotations("-- materialize")
.for_script("f/shop/orders_𐐀")
.materialize
.unwrap();
assert_eq!(m.target_path, "main/orders__");
}
#[test]
+1 -1
View File
@@ -202,7 +202,7 @@ type ParsedMaterialize = NonNullable<ParseAssetsRaw["materialize"]>;
export function withDefaultTable(m: ParsedMaterialize, scriptPath: string): ParsedMaterialize {
// `<lake>/<table>` and `<lake>.<table>` already name a table.
if (m.target_kind !== "ducklake" || /[/.]/.test(m.target_path)) return m;
const name = (scriptPath.split("/").pop() ?? "").trim().replace(/[^A-Za-z0-9_]/g, "_");
const name = (scriptPath.split("/").pop() ?? "").trim().replace(/[^A-Za-z0-9_]/gu, "_");
// The generated SQL names the table unquoted, so it cannot start with a digit.
const table = /^[0-9]/.test(name) ? `_${name}` : name;
return table ? { ...m, target_path: `${m.target_path}/${table}` } : m;
@@ -1053,6 +1053,8 @@ test("withDefaultTable names an untabled DuckLake target after the script", () =
expect(withDefaultTable(lakeOnly, "f/shop/orders-daily").target_path).toBe(
"main/orders_daily",
);
// One `_` per character, as the Rust rule counts them, whatever its width.
expect(withDefaultTable(lakeOnly, "f/shop/orders_𐐀").target_path).toBe("main/orders__");
for (const target_path of ["main/orders", "main.orders"]) {
expect(
withDefaultTable({ target_kind: "ducklake", target_path }, "f/shop/x").target_path,
@@ -318,5 +318,9 @@ describe('materialize without a table', () => {
expect(
parsePipelineAnnotations('-- materialize', 'f/shop/2026_orders').materialize?.targetPath
).toBe('main/_2026_orders')
// One `_` per character, as the Rust rule counts them, whatever its width.
expect(
parsePipelineAnnotations('-- materialize', 'f/shop/orders_𐐀').materialize?.targetPath
).toBe('main/orders__')
})
})
@@ -839,7 +839,7 @@ export function forScript(ann: PipelineAnnotations, scriptPath: string): Pipelin
export function materializeTargetPath(m: MaterializeSpec, scriptPath: string): string {
// `<lake>/<table>` and `<lake>.<table>` already name a table.
if (m.targetKind !== 'ducklake' || /[/.]/.test(m.targetPath)) return m.targetPath
const name = (scriptPath.split('/').pop() ?? '').trim().replace(/[^A-Za-z0-9_]/g, '_')
const name = (scriptPath.split('/').pop() ?? '').trim().replace(/[^A-Za-z0-9_]/gu, '_')
// The generated SQL names the table unquoted, so it cannot start with a digit.
return name ? `${m.targetPath}/${/^[0-9]/.test(name) ? `_${name}` : name}` : m.targetPath
}