Skip to content

Conversation

@scovich
Copy link
Contributor

@scovich scovich commented Jun 25, 2025

Which issue does this PR close?

Rationale for this change

As a follow-up to #7738, we should verify that the unscaled integer value fits in the max precision (scale factor was already validated).

What changes are included in this PR?

Add the missing checking, and add missing unit tests for both precision and scale.

Also move the VariantDecimalXX structs to their own mod.

Are these changes tested?

Yes, see above.

Are there any user-facing changes?

No. Public re-rexport of the moved structs.

@github-actions github-actions bot added the parquet Changes to the parquet crate label Jun 25, 2025
@scovich
Copy link
Contributor Author

scovich commented Jun 25, 2025

Attn @Weijun-H @alamb

@@ -1,5 +1,3 @@
use std::ops::Deref;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure how this ended up here...

Copy link
Contributor

Choose a reason for hiding this comment

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

we can blame the IDE perhaps

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ShortString<'a>(pub(crate) &'a str);

/// Represents a 4-byte decimal value in the Variant format.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to decimal.rs

Comment on lines +34 to +35
const MAX_PRECISION: u32 = 9;
const MAX_UNSCALED_VALUE: u32 = 10_u32.pow(Self::MAX_PRECISION) - 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hoisted up and renamed the existing constant, and used it to define the other constant

Comment on lines +41 to +43
"Scale {} of a 4-byte decimal cannot exceed the max precision {}",
scale,
Self::MAX_PRECISION,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the error message to reference the constant instead of a magic number

Comment on lines +47 to +54
// Validate that the integer value fits within the precision
if integer.unsigned_abs() > Self::MAX_UNSCALED_VALUE {
return Err(ArrowError::InvalidArgumentError(format!(
"{} is too large to store in a 4-byte decimal with max precision {}",
integer,
Self::MAX_PRECISION
)));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The newly added validation

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.

Love it

@alamb
Copy link
Contributor

alamb commented Jun 25, 2025

Thank you @scovich

CC @Weijun-H in case you are interested as well

@alamb alamb merged commit d6c421c into apache:main Jun 25, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet Changes to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants