-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
refactor byte_to_string and string_to_byte #7091
Conversation
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.
Thank you @parkma99 -- this is a nice cleanup. I left some thoughts about how to improve it more if you want.
However I think we can merge it now too as it is an improvement over what is on main
datafusion/proto/src/common.rs
Outdated
} | ||
|
||
pub fn str_to_byte(s: &String) -> Result<u8> { | ||
pub fn str_to_byte(s: &String, flag: &str) -> Result<u8> { |
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 know this PR didn't introduce this change, but str_to_bytes
doesn't need to be pub
:
pub fn str_to_byte(s: &String, flag: &str) -> Result<u8> { | |
fn str_to_byte(s: &String, flag: &str) -> Result<u8> { |
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 might also be clearer if the name of flag
was something like description
datafusion/proto/src/common.rs
Outdated
} | ||
Ok(s.as_bytes()[0]) | ||
} | ||
|
||
pub fn byte_to_string(b: u8) -> Result<String> { | ||
pub fn byte_to_string(b: u8, flag: &str) -> Result<String> { |
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.
pub fn byte_to_string(b: u8, flag: &str) -> Result<String> { | |
fn byte_to_string(b: u8, flag: &str) -> Result<String> { |
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 am confuing about this, str_to_bytes
is called in other file.
datafusion/proto/src/common.rs
Outdated
return Err(DataFusionError::Internal( | ||
"Invalid CSV delimiter".to_owned(), | ||
)); | ||
return Err(DataFusionError::Internal(format!("Invalid CSV {flag}"))); |
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 think more specific error messages are more helpful:
return Err(DataFusionError::Internal(format!("Invalid CSV {flag}"))); | |
return Err(DataFusionError::Internal(format!("Invalid CSV {flag}: expected single character, got {s}"))); |
datafusion/proto/src/common.rs
Outdated
let b = &[b]; | ||
let b = std::str::from_utf8(b) | ||
.map_err(|_| DataFusionError::Internal("Invalid CSV delimiter".to_owned()))?; | ||
.map_err(|_| DataFusionError::Internal(format!("Invalid CSV {flag}")))?; |
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.
.map_err(|_| DataFusionError::Internal(format!("Invalid CSV {flag}")))?; | |
.map_err(|_| DataFusionError::Internal(format!("Invalid CSV {flag}: can not represent {b:0x} as utf8")))?; |
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.
Thanks @parkma99
Thanks for reviewing @alamb @jackwener |
Which issue does this PR close?
Closes #6926
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?