Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Cannot parse CSV with newlines #642

Merged
merged 8 commits into from
Jan 28, 2025
Merged

[FIX] Cannot parse CSV with newlines #642

merged 8 commits into from
Jan 28, 2025

Conversation

TungstnBallon
Copy link
Contributor

Closes #608.

Problem: The TextFile IOType contains a list of lines, which CSVInterpreter considers a string value containing a newline as two different rows.
Solution: Change TextFile to contain a single string, not a list of lines. This means that existing blocks relying on the lines being already split have been adapted as well. E.g. the TextLineDeleter splits the string into lines, deletes the lines required and joins the lines back into a single string.

Copy link
Contributor

@joluj joluj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work 🎉

libs/execution/src/lib/util/file-util.ts Show resolved Hide resolved
@@ -2,7 +2,10 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

import { parseString as parseStringAsCsv } from '@fast-csv/parse';
// eslint-disable-next-line unicorn/prefer-node-protocol
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I asked this before, why not just add the node protocol?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

importing node:assert gives me this linter error:

'node:assert' import is restricted from being used. Please use the library `assert` instead to keep browser compatibility. You might need to disable rule `unicorn/prefer-node-protocol` to do so  no-restricted-imports`

Comment on lines +63 to +72
(reason) => {
assert(typeof reason === 'string');
return R.err({
message: reason,
diagnostic: {
node: context.getCurrentNode(),
property: 'name',
},
});
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow I didn't know that you could add a second parameter to .then :D I still prefer using .catch because it think has more semantic value, but I don't mind using it.

@joluj
Copy link
Contributor

joluj commented Jan 27, 2025

I was wondering if we should add improvements for selecting just the first couple of rows.

I think it's a very common use case, and removing the first couple of rows of a large text file could lead to performance issue (if I understood the algorithm correctly).
Not something we need to tackle, but maybe keep in mind.

@TungstnBallon TungstnBallon merged commit 902ba93 into main Jan 28, 2025
3 checks passed
@TungstnBallon TungstnBallon deleted the 608-csv-newlines branch January 28, 2025 09:56
@github-actions github-actions bot locked and limited conversation to collaborators Jan 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Cannot parse CSV with newlines
2 participants