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

Add builder style APIs For Field: with_name, with_data_type and with_nullable #2024

Merged
merged 2 commits into from Jul 8, 2022

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jul 7, 2022

Which issue does this PR close?

Closes #1934

Rationale for this change

The lack of such an API caused me consternation in apache/datafusion#2803 and https://github.com/influxdata/influxdb_iox/pull/5021

Basically I want to be able to change a field's nullability like

let new_field = old_field.clone().with_nullable(false);

But instead I have to do something like

 // make a copy of the field, but allow it to be nullable
 Field::new(f.name(), f.data_type().clone(), true)
   .with_metadata(f.metadata().cloned())

What changes are included in this PR?

  1. Add Field::with_name
  2. Add Field::with_data_type
  3. Add Field::with_nullability
  4. Add examples (which also serve as tests)
  5. Update additional documentation

Are there any user-facing changes?

yes, new APIs and better docs

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jul 7, 2022
@alamb alamb marked this pull request as ready for review July 7, 2022 20:03
arrow/src/datatypes/field.rs Outdated Show resolved Hide resolved
arrow/src/datatypes/field.rs Outdated Show resolved Hide resolved
arrow/src/datatypes/field.rs Outdated Show resolved Hide resolved
Co-authored-by: Liang-Chi Hsieh <viirya@gmail.com>
@alamb alamb changed the title Add builder style APIs with_name, with_data_type and with_nullable to Field Add builder style APIs For Field: with_name, with_data_type and with_nullable Jul 7, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #2024 (74085fa) into master (e59b023) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #2024      +/-   ##
==========================================
- Coverage   83.42%   83.41%   -0.02%     
==========================================
  Files         222      222              
  Lines       57906    57915       +9     
==========================================
+ Hits        48306    48307       +1     
- Misses       9600     9608       +8     
Impacted Files Coverage Δ
arrow/src/datatypes/field.rs 54.59% <0.00%> (-1.29%) ⬇️
parquet_derive/src/parquet_field.rs 65.98% <0.00%> (+0.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e59b023...74085fa. Read the comment docs.

Copy link
Contributor

@HaoYang670 HaoYang670 left a comment

Choose a reason for hiding this comment

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

LGTM!
Nit: It seems like the 3 methods are not covered in the Codecov result, although they have been tested by docs.

@tustvold tustvold merged commit 7542f7d into apache:master Jul 8, 2022
@alamb alamb deleted the alamb/field_builder branch July 8, 2022 14:51
@alamb
Copy link
Contributor Author

alamb commented Jul 30, 2022

Related to #1091

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add builder style methods to Field
6 participants