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 Decimal256Builder and Decimal256Array; Decimal arrays now implement BasicDecimalArray trait #2000

Merged
merged 8 commits into from Jul 8, 2022

Conversation

viirya
Copy link
Member

@viirya viirya commented Jul 4, 2022

Which issue does this PR close?

Closes #1999.

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@viirya viirya marked this pull request as draft July 4, 2022 08:30
@github-actions github-actions bot added arrow Changes to the arrow crate parquet Changes to the parquet crate labels Jul 4, 2022
@viirya
Copy link
Member Author

viirya commented Jul 4, 2022

Marked as draft now and I will add some tests and dedup some codes.

@liukun4515
Copy link
Contributor

liukun4515 commented Jul 5, 2022

If it is ready, please @ me. @viirya

@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2022

Codecov Report

Merging #2000 (7c3e00f) into master (2309157) will decrease coverage by 0.00%.
The diff coverage is 83.33%.

@@            Coverage Diff             @@
##           master    #2000      +/-   ##
==========================================
- Coverage   83.58%   83.58%   -0.01%     
==========================================
  Files         222      222              
  Lines       57529    57603      +74     
==========================================
+ Hits        48088    48145      +57     
- Misses       9441     9458      +17     
Impacted Files Coverage Δ
arrow/src/array/equal_json.rs 87.89% <0.00%> (-1.81%) ⬇️
arrow/src/array/iterator.rs 96.11% <ø> (ø)
arrow/src/array/mod.rs 100.00% <ø> (ø)
arrow/src/array/ord.rs 69.17% <ø> (ø)
arrow/src/compute/kernels/cast.rs 95.79% <ø> (ø)
arrow/src/compute/kernels/sort.rs 95.67% <ø> (ø)
arrow/src/compute/kernels/take.rs 95.27% <ø> (ø)
arrow/src/csv/reader.rs 89.89% <ø> (ø)
arrow/src/util/decimal.rs 91.50% <ø> (ø)
arrow/src/util/display.rs 73.17% <ø> (ø)
... and 8 more

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 2309157...7c3e00f. Read the comment docs.

@viirya viirya marked this pull request as ready for review July 5, 2022 21:26
@viirya
Copy link
Member Author

viirya commented Jul 6, 2022

cc @alamb @tustvold @liukun4515

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.

I think the code looks good to me 👍 Nice work @viirya and thank you!

I have some comments regarding checking for mismatch in precision / scale between the builder and values, but otherwise I think this PR looks good to me.

pub fn append_value(&mut self, value: &Decimal256) -> Result<()> {
let value_as_bytes = value.raw_value();

if self.builder.value_length() != value_as_bytes.len() as i32 {
Copy link
Contributor

@alamb alamb Jul 6, 2022

Choose a reason for hiding this comment

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

I wonder if we also need to check the precision and scale of value (and either error if they don't match the builder or do conversion if required) 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I think we should. It is a cheap check too so I think okay.

bytes = vec![0; 32];
bytes[0..16].clone_from_slice(&0_i128.to_le_bytes());
bytes[15] = 128;
let value = Decimal256::try_new_from_bytes(40, 6, bytes.as_slice()).unwrap();
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 we should add a test for appending a value that has a precision/scale other than 40. 6, as I mentioned above

@tustvold
Copy link
Contributor

tustvold commented Jul 7, 2022

Should I be reviewing this or #2006, they seem to implement the same functionality?

@viirya
Copy link
Member Author

viirya commented Jul 7, 2022

@tustvold I'd prefer this. #2006 is just for showing the alternative concept. But there is some issues. Please review this, thanks.

/// See [`Decimal256Array`] for example.
#[derive(Debug)]
pub struct Decimal256Builder {
builder: FixedSizeListBuilder<UInt8Builder>,
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be more straightforward to build decimal array based on FixedSizeBinaryBuilder. I will file a followup issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Create #2026 to track this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also confused about that we use the the FixedSizeListBuilder to store decimal data in the decimal builder.

@alamb
Copy link
Contributor

alamb commented Jul 8, 2022

@tustvold is this one good to go (for arrow 18?)

@alamb alamb merged commit ca1bfb8 into apache:master Jul 8, 2022
@alamb alamb changed the title Add Decimal256Builder and Decimal256Array Add Decimal256Builder and Decimal256Array Jul 8, 2022
@alamb alamb added the api-change Changes to the arrow API label Jul 8, 2022
@alamb alamb changed the title Add Decimal256Builder and Decimal256Array Add Decimal256Builder and Decimal256Array; Decimal arrays now implement BasicDecimalArray trait Jul 8, 2022
@alamb
Copy link
Contributor

alamb commented Jul 8, 2022

I see now that @liukun4515 asked to be pinged on this PR for review, which @viirya did but then I merged it prior to @liukun4515 having a chance to review.

@liukun4515 I will make the 18.0.0 release candidate but if you find issues with the API or some other reason we should not release 18.0.0 with this change in it, please let me know and we can make changes prior to release.

@liukun4515
Copy link
Contributor

I see now that @liukun4515 asked to be pinged on this PR for review, which @viirya did but then I merged it prior to @liukun4515 having a chance to review.

@liukun4515 I will make the 18.0.0 release candidate but if you find issues with the API or some other reason we should not release 18.0.0 with this change in it, please let me know and we can make changes prior to release.

I see now that @liukun4515 asked to be pinged on this PR for review, which @viirya did but then I merged it prior to @liukun4515 having a chance to review.

@liukun4515 I will make the 18.0.0 release candidate but if you find issues with the API or some other reason we should not release 18.0.0 with this change in it, please let me know and we can make changes prior to release.

Sorry for the later reply, I am busy with other task.
This pr looks great for me.
And from #2000 (comment), it's better to refactor the builder and generate the array data from fixed list builder to fixed binary builder.

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 parquet Changes to the parquet crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Decimal256Builder and Decimal256Array
6 participants