-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Properly determine CSV delimiter #17459
Merged
lunny
merged 32 commits into
go-gitea:main
from
richmahn:richmahn-16558-guess-delimiter
Oct 30, 2021
Merged
Changes from 18 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
fc8dd28
Fixes #16558 CSV delimiter determiner
richmahn 6fe4f9f
Merge remote-tracking branch 'origin/main' into richmahn-16558-guess-…
richmahn c99d94e
Merge remote-tracking branch 'origin/main' into richmahn-16558-guess-…
richmahn 58e98c5
Merge remote-tracking branch 'origin/main' into richmahn-16558-guess-…
richmahn 56f0995
Fixes #16558 - properly determine CSV delmiiter
richmahn 7da56ba
Moves quoteString to a new function
richmahn 5b3a8d9
Adds big test with lots of commas for tab delimited csv
richmahn b0a6290
Adds comments
richmahn 79ee659
Shortens the text of the test
richmahn f508559
Removes single quotes from regexp as only double quotes need to be se…
richmahn e0f2862
Fixes spelling
richmahn ab0583c
Merge branch 'main' into richmahn-16558-guess-delimiter
wxiaoguang e466ab7
Fixes check of length as it probalby will only be 1e4, not greater
richmahn a54e6ac
Merge branch 'richmahn-16558-guess-delimiter' of github.com:richmahn/…
richmahn 62d10e3
Makes sample size a const, properly removes truncated line
richmahn 0a2f06d
Makes sample size a const, properly removes truncated line
richmahn 85eda5f
Fixes comment
richmahn fc02c05
Fixes comment
richmahn baf37d3
tests for FormatError() function
richmahn 32a9c36
Adds logic to find the limiter before or after a quoted value
richmahn e8ac38a
Merge remote-tracking branch 'origin/main' into richmahn-16558-guess-…
richmahn feabe0e
Simplifies regex
richmahn f808d73
Merge branch 'main' into richmahn-16558-guess-delimiter
zeripath 0084114
Error tests
richmahn 967da1d
Merge branch 'richmahn-16558-guess-delimiter' of github.com:richmahn/…
richmahn 683def1
Error tests
richmahn 95ede28
Update modules/csv/csv.go
richmahn b938db4
Update modules/csv/csv.go
richmahn 772095d
Adds comments
richmahn 8a54f7a
Merge branch 'main' into richmahn-16558-guess-delimiter
wxiaoguang 059ae3d
Update modules/csv/csv.go
zeripath 88a2642
Merge branch 'main' into richmahn-16558-guess-delimiter
wxiaoguang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we count file size in decimal or binary units?
Because in binary, this number should be a bit larger (10192, or 2^13, if I'm not mistaken).
I know that oftentimes, compilers prefer powers of two as those can be optimized better. I guess that should be the case here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't something I added, as it was always a sample size of 10,000. So yeah, it is using 'k' here in the comments that were there before I worked on this as decimal. It's just an arbitrary sample size. I made it a constant so I can check if we may have a truncated line when getting 10 lines from that sample text.
See: https://github.com/go-gitea/gitea/blob/main/modules/csv/csv.go#L34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. And I'm arguing to set it to a value that the compiler will be able to optimize better.
One small correction, though: Apparently, I thought that 2^(11+1) would be 5096, instead of 4096.
So, what I am asking for is to at best use either
1<<13
(8192
) or1<<14
(16384
) bytes.Which do you prefer?
Or do you prefer the
10000
, which is slightly easier to read, but will be worse in runtime performance?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't matter whatever we choose, 1e4, 16384, 8192, all work, you won't feel any difference.
We are not writing an OS or a memory allocation library, we won't benefit from the page-aligned memory size.
We do not need to struggle on such trivial details.