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

Minor: Allow Field::new and Field::new_with_dict to take existing String as well as &str #3288

Merged
merged 1 commit into from
Dec 8, 2022

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Dec 7, 2022

Which issue does this PR close?

N/A

Rationale for this change

Sometimes (e.g. apache/datafusion#4534) a caller already has an owned String but today Field requires &str which forces another clone

What changes are included in this PR?

Change Field::new() to take impl Into<String> so that anything that implements impl Into<String> , such as String, can be passed

Are there any user-facing changes?

The API is changed but is backwards compatible

@github-actions github-actions bot added the arrow Changes to the arrow crate label Dec 7, 2022
@alamb alamb changed the title Minor: Allow Field::new and Field::new_with_dict to take existing String as well as &str Minor: Allow Field::new and Field::new_with_dict to take existing String as well as &str Dec 7, 2022
Comment on lines +489 to +493
fn test_new_with_string() {
// Fields should allow owned Strings to support reuse
let s = String::from("c1");
Field::new(s, DataType::Int64, false);
}
Copy link
Member

@viirya viirya Dec 7, 2022

Choose a reason for hiding this comment

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

Not sure if I understand the purpose clearly. Doesn't it work for now:

let s = String::from("c1");
Field::new(&s, DataType::Int64, false);

Copy link
Contributor

Choose a reason for hiding this comment

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

Internally that will create a new memory allocation and copy the string data across, effectively this saves a Clone

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation!

Copy link
Member

@viirya viirya left a comment

Choose a reason for hiding this comment

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

BTW, I think this represents an api-change?

@viirya viirya added the api-change Changes to the arrow API label Dec 8, 2022
@viirya
Copy link
Member

viirya commented Dec 8, 2022

Added the label. Feel free to remove it if you think it is not necessary.

@tustvold tustvold merged commit 16484a6 into apache:master Dec 8, 2022
@alamb
Copy link
Contributor Author

alamb commented Dec 8, 2022

BTW, I think this represents an api-change?

I agree it is technically an API change, I think it will be backwards compatible in the sense that any code that created Field::new() previously will continue to work. Normally I thought api-change label is applied to breaking changes, but it is ambiguous.

The backwards compatible story is consistent with the fact that no tests needed to be changed

@tustvold
Copy link
Contributor

tustvold commented Dec 8, 2022

previously will continue to work

Technically this is still a breaking change, as it could now fail to infer the type of an expression where previously it could. However, in the past we haven't considered this sort of change "breaking".

@alamb
Copy link
Contributor Author

alamb commented Dec 8, 2022

Well let's leave the label on it then

@alamb alamb deleted the alamb/field_new branch December 8, 2022 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-change Changes to the arrow API arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants