-
Notifications
You must be signed in to change notification settings - Fork 114
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
CSV parser fails with mixed quoting and non-standard row_sep #107
Comments
I'm using the version included in ruby 2.6.5, btw! |
The stack trace indicates that it's failing in |
Why do you want to use |
We're using this because we're interfacing with other systems that have very poor support for CSV, and get confused by newlines in quoted fields. That said, these files are created and then transformed by our software before being passed off to the other software (various RDBMSes) so during that first, internal phase, we could just use the default row/column separators, and avoid needing to parse the non-standard format. If you don't want to support it, that's ok but an error should probably be raised when reading with non-standard row/col separators. |
Could you show the real CSV that has problem? |
The CSV was using "|\n" as a row separator. This CSV is used for an export/import process that involves creating CSV files, transforming them, and then finally importing them into MySQL, Postgres, Oracle, etc. We use a "|\n" separator in the final CSV files to overcome very poor CSV support in some of these databases. It used to be the case that the initial CSV files were written with the "|\n" row separator, which meant that we had to support it when reading the CSV files for the transformation & filtering step. The generated CSV was not any more complicated than what was produced in the initial example I provided. After discovering this issue, I have modified our system to only use the "|\n" separator in the final step - right before the file is imported into the other SQL databases. |
Ah, sorry. I want to know the input of your transformation system. I think that the following is a situation of this case:
I want to know a sample content of |
The whole process starts with our database, so the situation is more like:
Steps 1-2 happen daily, steps 3,4,5 are repeated many times with the output of steps 1-2. The system has been modified to now work like this:
With this change, we no longer need to read CSV files with The reason we were reading with that row separator is because it is convenient to use the same row separator from start to end of the process. It's OK to have to use standard CSV in steps 1 and 2. The actual data we are processing is not relevant to the process or the usage of that row separator. Therefore, in my opinion, the main bug is that you can set anything you want as |
Thanks. I understand. |
In the example above, the parser will raise a
CSV::MalformedCSVError (Unquoted fields do not allow new line <"\n"> in line 2.)
error.It will succeed if any of the following are done:
force_quotes: true
togenerate
row_sep: "\n"
Therefore, the problem seems to be that a non-standard
row_sep
+ lines with a field being quoted in one row and unquoted in the next.The text was updated successfully, but these errors were encountered: