feat(import): support comma decimal separator for CSV/TSV
This commit is contained in:
15 files changed
+184
-6
No files matched your search
@@ -45,6 +45,24 @@ describe("tableImport", () => {
|
||||
expect(legacyEmptyField.emptyStringAsNull).toBe(true);
|
||||
});
|
||||
|
||||
it("passes the decimal separator only for delimited sources", () => {
|
||||
const settings = {
|
||||
delimiter: ";",
|
||||
decimalSeparator: ",",
|
||||
textEncoding: "auto" as const,
|
||||
titleRow: 1,
|
||||
dataStartRow: 2,
|
||||
lastDataRow: 0,
|
||||
trimValues: false,
|
||||
emptyStringAsNull: false,
|
||||
jsonShape: "auto" as const,
|
||||
};
|
||||
expect(buildTableImportParseOptions({ ...settings, format: "delimited" }).decimalSeparator).toBe(",");
|
||||
expect(buildTableImportParseOptions({ ...settings, format: "csv" }).decimalSeparator).toBe(",");
|
||||
expect(buildTableImportParseOptions({ ...settings, format: "tsv" }).decimalSeparator).toBe(",");
|
||||
expect(buildTableImportParseOptions({ ...settings, format: "json" }).decimalSeparator).toBeNull();
|
||||
});
|
||||
|
||||
it("formats import elapsed time for progress and terminal summaries", () => {
|
||||
expect(formatTableImportElapsed(0)).toBe("0 ms");
|
||||
expect(formatTableImportElapsed(999)).toBe("999 ms");
|
||||
|
||||
@@ -5494,6 +5494,7 @@ export interface TableImportColumnMapping {
|
||||
|
||||
export interface TableImportParseOptions {
|
||||
delimiter?: string | null;
|
||||
decimalSeparator?: string | null;
|
||||
encoding?: TableImportTextEncoding | null;
|
||||
hasHeader?: boolean | null;
|
||||
titleRow?: number | null;
|
||||
|
||||
@@ -86,6 +86,7 @@ export function tableImportProgressPercent(progress: TableImportProgressLike | n
|
||||
export interface TableImportParseSettings {
|
||||
format: TableImportSourceFormat;
|
||||
delimiter: string;
|
||||
decimalSeparator?: "." | ",";
|
||||
textEncoding: TableImportTextEncoding;
|
||||
titleRow: number;
|
||||
dataStartRow: number;
|
||||
@@ -114,6 +115,7 @@ export function buildTableImportParseOptions(settings: TableImportParseSettings)
|
||||
const isTextSource = isDelimited || settings.format === "sql";
|
||||
return {
|
||||
delimiter: settings.format === "tsv" ? "\\t" : settings.format === "csv" ? "," : settings.delimiter,
|
||||
decimalSeparator: isDelimited ? (settings.decimalSeparator ?? ".") : null,
|
||||
encoding: isTextSource ? settings.textEncoding : null,
|
||||
titleRow: settings.titleRow,
|
||||
dataStartRow: settings.dataStartRow,
|
||||
|
||||
Reference in new issue
Block a user