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

Validate decimal256 with i256 directly #3025

Merged
merged 4 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions arrow-array/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use crate::delta::shift_months;
use crate::OffsetSizeTrait;
use arrow_buffer::i256;
use arrow_data::decimal::{
validate_decimal256_precision_with_lt_bytes, validate_decimal_precision,
DECIMAL128_MAX_PRECISION, DECIMAL128_MAX_SCALE, DECIMAL256_MAX_PRECISION,
DECIMAL256_MAX_SCALE, DECIMAL_DEFAULT_SCALE,
validate_decimal256_precision, validate_decimal_precision, DECIMAL128_MAX_PRECISION,
DECIMAL128_MAX_SCALE, DECIMAL256_MAX_PRECISION, DECIMAL256_MAX_SCALE,
DECIMAL_DEFAULT_SCALE,
};
use arrow_schema::{ArrowError, DataType, IntervalUnit, TimeUnit};
use chrono::{Duration, NaiveDate};
Expand Down Expand Up @@ -554,7 +554,7 @@ impl DecimalType for Decimal256Type {
}

fn validate_decimal_precision(num: i256, precision: u8) -> Result<(), ArrowError> {
validate_decimal256_precision_with_lt_bytes(&num.to_le_bytes(), precision)
validate_decimal256_precision(num, precision)
}
}

Expand Down
9 changes: 9 additions & 0 deletions arrow-buffer/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ impl i256 {
}
}

/// Create an integer value from its representation as high and low byte arrays in little-endian.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we just use the from_le_bytes above?

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally wanted that. But I cannot make from_le_bytes as const fn.

error[E0015]: cannot call non-const fn `Result::<[u8; 16], TryFromSliceError>::unwrap` in constant functions

Copy link
Contributor

Choose a reason for hiding this comment

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

#[inline]
pub const fn from_const_le_bytes(low_bytes: [u8; 16], high_bytes: [u8; 16]) -> Self {
Self {
high: i128::from_le_bytes(high_bytes),
low: u128::from_le_bytes(low_bytes),
}
}

/// Create an integer value from its representation as a byte array in little-endian.
#[inline]
pub fn from_be_bytes(b: [u8; 32]) -> Self {
Expand Down
Loading