Repository navigation
GH-51275: [C++][GLib] Allow the CSV Reader to accept multi-character delimiters #51286
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
Open
HuaHuaY
wants to merge
6
commits into
apache:main
Choose a base branch
from
HuaHuaY:strengthen_csv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+577
−103
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b94b6fe
allow the CSV Reader to accept multi-character delimiters
HuaHuaY bd6eb40
fix ci
HuaHuaY dbe45a9
address review comments
HuaHuaY a7912ea
address review comments
HuaHuaY 19961af
fix ci
HuaHuaY 612b963
address review comments
HuaHuaY 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,39 @@ namespace csv { | |
| ParseOptions ParseOptions::Defaults() { return ParseOptions(); } | ||
|
|
||
| Status ParseOptions::Validate() const { | ||
| if (ARROW_PREDICT_FALSE(delimiter == '\n' || delimiter == '\r')) { | ||
| return Status::Invalid("ParseOptions: delimiter cannot be \\r or \\n"); | ||
| // The chunker handles escapes before delimiter matching, so allowing the escape | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it cleaner to consolidate the two cases like below? std::string invalid_chars = "\r\n";
if (escaping) {
invalid_chars.push_back(escape_char);
}
const bool use_delimiter_string = !delimiter_string.empty();
const auto invalid_pos =
use_delimiter_string ? delimiter_string.find_first_of(invalid_chars)
: invalid_chars.find(delimiter);
if (invalid_pos != std::string::npos) {
return Status::Invalid("ParseOptions: delimiter contains an invalid character");
}
const char delimiter_first_byte =
use_delimiter_string ? delimiter_string.front() : delimiter;
if (quoting && delimiter_first_byte == quote_char) {
return Status::Invalid(
"ParseOptions: delimiter cannot start with the quote character");
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, by doing this, we lose the specific reason for the error. |
||
| // character in a delimiter could make it disagree with the parser. | ||
| if (escaping) { | ||
|
HuaHuaY marked this conversation as resolved.
|
||
| if (delimiter_string.empty()) { | ||
| if (delimiter == escape_char) { | ||
| return Status::Invalid( | ||
| "ParseOptions: delimiter cannot be the escape character when escaping is " | ||
| "enabled"); | ||
| } | ||
| } else if (delimiter_string.find(escape_char) != std::string::npos) { | ||
| return Status::Invalid( | ||
| "ParseOptions: delimiter_string cannot contain the escape character when " | ||
| "escaping is enabled"); | ||
| } | ||
| } | ||
| // Line endings delimit records and therefore cannot be part of a field delimiter. | ||
| if (delimiter_string.empty()) { | ||
| if (ARROW_PREDICT_FALSE(delimiter == '\n' || delimiter == '\r')) { | ||
| return Status::Invalid("ParseOptions: delimiter cannot be \\r or \\n"); | ||
| } | ||
| } else if (ARROW_PREDICT_FALSE(delimiter_string.find_first_of("\r\n") != | ||
| std::string::npos)) { | ||
| return Status::Invalid("ParseOptions: delimiter_string cannot contain \\r or \\n"); | ||
| } | ||
| // The chunker handles quotes before delimiter matching at field boundaries, so | ||
| // allowing the quote character at the start of a delimiter could make it disagree | ||
| // with the parser. | ||
| const char delimiter_first_byte = | ||
| delimiter_string.empty() ? delimiter : delimiter_string.front(); | ||
| if (ARROW_PREDICT_FALSE(quoting && delimiter_first_byte == quote_char)) { | ||
| return Status::Invalid( | ||
| "ParseOptions: delimiter cannot start with the quote character when quoting is " | ||
| "enabled"); | ||
| } | ||
| if (ARROW_PREDICT_FALSE(quoting && (quote_char == '\n' || quote_char == '\r'))) { | ||
| return Status::Invalid("ParseOptions: quote_char cannot be \\r or \\n"); | ||
|
|
||
Oops, something went wrong.
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.
This GLib part changes are correct but you can revert this in this PR. I can work on the GLib part including multi-character delimiters support as a follow-up task after this is merged.
Uh oh!
There was an error while loading. Please reload this page.
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.
I can revert this part of the code tomorrow. However, this PR adds a
std::stringfield inParseOptions, which will break two CI tests because the reverted initialization code is missing in GLib.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.
OK. If this part is required to keep our CI green, let's keep this part in this PR.