-
Notifications
You must be signed in to change notification settings - Fork 22
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
'continue' restart doesn't work in cl-csv:read-csv (without :sample) #35
Comments
Thanks for the well written ticket! I don't have much lisp time in my life anymore, and its hard to say when I will have time to update this. I am not sure the answer to your question as to why its like that. It probably lies in the fact that the parser/readers were rewritten a time or two, and that perhaps one of those dropped the continues restarts when we added the I'ld be happy to look at any patches that pass the test suite that you submit in the mean time. I do think that having the restarts makes sense (depending on the speed implications of having them). The could/should be triggered by the existing variable My best guess looking now: parser.lisp#420
I'ld like to get to this, but with it not being paying work, its hard to devote time to it right now. |
Understood, Russ; I know what you mean, and appreciate the quick proposal for a fix. Before I change anything, I'd like to make sure I understand the relationship between However, in the current Ideally there would always be two ways to recover, with the (I suppose one could argue that a nil value for I'd need to study the code a bit more to see how the restarts might be made to work consistently across all the various external functions/macros. It's a bit more involved than simply wrapping the call in |
I think that you are correct in the Thus if you were trying to write "fast as possible" code, you would probably want to turn off the continue bindings. Whether or not that makes sense as a trade off is probably work load related. That said, it seems (based on the other open ticket) that the optimizations previously made dont necessarily hold anymore and perhaps its better to code for usefulness rather than performance
|
Hrm... Another interesting aspect is that: I also see that this is difficult because when we switched from a state machine. The continue, needs to reset the parse table / reader and advance the stream to the next start of row |
I'm running cl-csv-20180831-git (the most recent version I see in Quicklisp) on SBCL 1.5.4. I've found the library to be really useful, and easy to work with; but I've noticed one discrepancy between its documentation and the code.
The cl-csv README.md file says:
in-csv iterate clause and read-csv support continue and filter restarts for errors occurring during read-csv-row
So, I added a handler-bind to my calling code which would catch csv-parse-error and invoke the continue restart. When I tried to read a bad CSV file I found that, as expected, the restart worked correctly for in-csv; while for read-csv-row and do-csv the Lisp debugger reported that no CONTINUE restart was active.
However, the debugger also complained that the restart wasn't active in read-csv, although the documentation says this should have worked. Interestingly, I found that if I call (read-csv stream :sample 999999), then the restart works again.
A quick look at csv.lisp shows that the in-csv macro invokes an internal function called restartable-read-row; and in-csv is used by read-csv-sample. In read-csv, if :sample is specified then read-csv-sample is called; but in the default case, read-csv-with-reader is called instead, and it appears that this does not support the restart.
This explains the behaviour I observed. But is this a bug in the read-csv code, or is it a documentation error - should callers of read-csv not be able to use this restart?
My opinion is that the restart is generally useful and that, as well as being fixed for read-csv, it could arguably be extended to read-csv-row and do-csv too. Am I missing something - is there a reason why it should be restricted to in-csv and read-csv? (Performance considerations, maybe?)
I'd love to be able to submit a pull request with this; but being a newcomer both to cl-csv and to Lisp itself, I'm not sure that would end well. Please have a look and see whether/how the restart can be made available; thanks very much.
The text was updated successfully, but these errors were encountered: