Skip to content
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

Merged
merged 4 commits into from
Jul 27, 2023

Conversation

parkma99
Copy link
Contributor

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?

Copy link
Contributor

@alamb alamb left a 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

}

pub fn str_to_byte(s: &String) -> Result<u8> {
pub fn str_to_byte(s: &String, flag: &str) -> Result<u8> {
Copy link
Contributor

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:

Suggested change
pub fn str_to_byte(s: &String, flag: &str) -> Result<u8> {
fn str_to_byte(s: &String, flag: &str) -> Result<u8> {

Copy link
Contributor

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

}
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> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn byte_to_string(b: u8, flag: &str) -> Result<String> {
fn byte_to_string(b: u8, flag: &str) -> Result<String> {

Copy link
Contributor Author

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.

return Err(DataFusionError::Internal(
"Invalid CSV delimiter".to_owned(),
));
return Err(DataFusionError::Internal(format!("Invalid CSV {flag}")));
Copy link
Contributor

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:

Suggested change
return Err(DataFusionError::Internal(format!("Invalid CSV {flag}")));
return Err(DataFusionError::Internal(format!("Invalid CSV {flag}: expected single character, got {s}")));

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}")))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map_err(|_| DataFusionError::Internal(format!("Invalid CSV {flag}")))?;
.map_err(|_| DataFusionError::Internal(format!("Invalid CSV {flag}: can not represent {b:0x} as utf8")))?;

Copy link
Member

@jackwener jackwener left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @parkma99

@parkma99
Copy link
Contributor Author

Thanks for reviewing @alamb @jackwener

@jackwener jackwener merged commit 60ea6de into apache:main Jul 27, 2023
@parkma99 parkma99 deleted the refactor/byte_to_string branch July 27, 2023 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor csv_delimiter_to_string and byte_to_string in common.rs in proto
3 participants