Skip to content

Commit

Permalink
Add support for missing columns in CSV (#163)
Browse files Browse the repository at this point in the history
* Increase chunk size

* Add support for not checking column correctness

* Fix for test format
  • Loading branch information
eatonphil authored Feb 3, 2022
1 parent 6ad1f24 commit 565c744
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
41 changes: 41 additions & 0 deletions desktop/panel/file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,45 @@ for (const subprocessName of RUNNERS) {
}
);
}

const regressions = [
{
file: path.join('testdata', 'csv', 'missing_columns.csv'),
expected: [
{ a: '3', b: '4' },
{ a: '1', b: '2' },
{ a: '5', b: '6' },
],
name: 'missing columns in csv',
},
];

for (const regression of regressions) {
describe('regression: ' + regression.name, () => {
test('correctness', () => {
const fp = new FilePanelInfo({
name: regression.file,
});

const panels = [fp];

return withSavedPanels(
panels,
(project) => {
// Grab result
const value = JSON.parse(
fs
.readFileSync(
getProjectResultsFile(project.projectName) + fp.id
)
.toString()
);

expect(value).toStrictEqual(regression.expected);
},
{ evalPanels: true, subprocessName }
);
});
});
}
}
2 changes: 2 additions & 0 deletions runner/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func withJSONArrayOutWriterFile(out io.Writer, cb func(w *JSONArrayWriter) error
func transformCSV(in io.Reader, out io.Writer, delimiter rune) error {
r := csv.NewReader(in)
r.Comma = delimiter
r.ReuseRecord = true
r.FieldsPerRecord = -1

return withJSONArrayOutWriterFile(out, func(w *JSONArrayWriter) error {
isHeader := true
Expand Down
4 changes: 4 additions & 0 deletions testdata/csv/missing_columns.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a,b
3,4
1,2,3
5,6

0 comments on commit 565c744

Please sign in to comment.