Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion docs/specs/row-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ null_sentinel || zero(width(T))
## Decimal

Decimals are encoded as their scaled signed integer storage value. The selected storage
width is the smallest decimal value type for the decimal precision:
width is the canonical width of the decimal precision, `DecimalDType::canonical_values_type()`:

| Precision | Storage |
| --- | --- |
Expand Down
4 changes: 1 addition & 3 deletions encodings/sparse/src/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use vortex_array::builders::VarBinViewBuilder;
use vortex_array::builders::builder_with_capacity_in;
use vortex_array::dtype::DType;
use vortex_array::dtype::DecimalDType;
use vortex_array::dtype::DecimalType;
use vortex_array::dtype::IntegerPType;
use vortex_array::dtype::NativeDecimalType;
use vortex_array::dtype::NativePType;
Expand Down Expand Up @@ -314,8 +313,7 @@ pub(super) fn execute_sparse(parts: SparseParts, ctx: &mut ExecutionCtx) -> Vort
})
}
DType::Decimal(decimal_dtype, nullability) => {
let canonical_decimal_value_type =
DecimalType::smallest_decimal_value_type(decimal_dtype);
let canonical_decimal_value_type = decimal_dtype.canonical_values_type();
let fill_decimal = fill_value.as_decimal();
match_each_decimal_value_type!(canonical_decimal_value_type, |D| {
execute_sparse_decimal::<D>(
Expand Down
3 changes: 1 addition & 2 deletions fuzz/src/array/sum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use vortex_array::arrays::bool::BoolArrayExt;
use vortex_array::dtype::BigCast;
use vortex_array::dtype::DType;
use vortex_array::dtype::DecimalDType;
use vortex_array::dtype::DecimalType;
use vortex_array::dtype::MAX_PRECISION;
use vortex_array::dtype::Nullability::Nullable;
use vortex_array::dtype::i256;
Expand Down Expand Up @@ -51,7 +50,7 @@ pub fn sum_canonical_array(
let limit = i256::from_i128(10)
.checked_pow(output_dtype.precision().into())
.vortex_expect("10^76 fits in i256");
let values_type = DecimalType::smallest_decimal_value_type(&output_dtype);
let values_type = output_dtype.canonical_values_type();
match_each_decimal_value_type!(values_type, |I| {
let limit = <I as BigCast>::from(limit)
.vortex_expect("precision limit fits native accumulator");
Expand Down
3 changes: 1 addition & 2 deletions vortex-array/src/aggregate_fn/fns/sum/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::ExecutionCtx;
use crate::arrays::DecimalArray;
use crate::dtype::DType;
use crate::dtype::DecimalDType;
use crate::dtype::DecimalType;
use crate::dtype::NativeDecimalType;
use crate::match_each_decimal_value_type;
use crate::scalar::DecimalValue;
Expand Down Expand Up @@ -46,7 +45,7 @@ pub(crate) fn accumulate_decimal(
.as_decimal_opt()
.vortex_expect("decimal sum result dtype");

let values_type = DecimalType::smallest_decimal_value_type(dtype);
let values_type = dtype.canonical_values_type();
match_each_decimal_value_type!(d.values_type(), |T| {
match_each_decimal_value_type!(values_type, |I| {
let initial: I = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use super::validity_uncompressed_size_in_bytes;
use crate::ExecutionCtx;
use crate::arrays::DecimalArray;
use crate::arrays::decimal::DecimalArrayExt;
use crate::dtype::DecimalType;

pub(super) fn decimal_uncompressed_size_in_bytes(
array: &DecimalArray,
Expand All @@ -17,10 +16,8 @@ pub(super) fn decimal_uncompressed_size_in_bytes(
let value_size = u64::try_from(array.len())
.map_err(|e| vortex_err!("Failed to convert decimal array length to u64: {e}"))?
.checked_mul(
u64::try_from(
DecimalType::smallest_decimal_value_type(&array.decimal_dtype()).byte_width(),
)
.map_err(|e| vortex_err!("Failed to convert decimal byte width to u64: {e}"))?,
u64::try_from(array.decimal_dtype().canonical_values_type().byte_width())
.map_err(|e| vortex_err!("Failed to convert decimal byte width to u64: {e}"))?,
)
.ok_or_else(|| vortex_err!("uncompressed size in bytes overflowed u64"))?;
let validity_size = validity_uncompressed_size_in_bytes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::arrays::listview::ListViewArraySlotsExt;
use crate::arrays::listview::ListViewRebuildMode;
use crate::arrays::primitive::PrimitiveArrayExt;
use crate::dtype::DType;
use crate::dtype::DecimalType;
use crate::dtype::IntegerPType;
use crate::match_each_integer_ptype;

Expand Down Expand Up @@ -100,7 +99,7 @@ fn referenced_elements_size(
}
DType::Decimal(decimal, _) => checked_len_mul(
referenced.count,
DecimalType::smallest_decimal_value_type(decimal).byte_width(),
decimal.canonical_values_type().byte_width(),
"decimal",
)?,
_ => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ use crate::arrays::ListView;
use crate::arrays::map::MapArraySlotsExt;
use crate::arrays::varbinview::BinaryView;
use crate::dtype::DType;
use crate::dtype::DecimalType;
use crate::dtype::Nullability::NonNullable;
use crate::dtype::PType;
use crate::expr::stats::Precision;
Expand Down Expand Up @@ -362,7 +361,7 @@ pub(crate) fn constant_uncompressed_size_in_bytes(
}
DType::Decimal(decimal_type, _) => checked_len_mul(
array.len(),
DecimalType::smallest_decimal_value_type(decimal_type).byte_width(),
decimal_type.canonical_values_type().byte_width(),
"decimal",
)?,
DType::Utf8(_) => constant_varbinview_value_size(
Expand Down Expand Up @@ -525,8 +524,8 @@ mod tests {

/// The size the array occupies once rebuilt through the canonical builders, which is the
/// layout [`UncompressedSizeInBytes`] is defined against: the builders normalize physical
/// widths that the input array is free to choose differently, picking the smallest decimal
/// value type for a precision and `u64` list-view offsets and sizes.
/// widths that the input array is free to choose differently, picking the canonical decimal
/// width of a precision and `u64` list-view offsets and sizes.
///
/// Builders no longer canonicalize their children, so the finished array is only canonical at
/// the top level - recursively canonicalize it before measuring.
Expand Down
3 changes: 1 addition & 2 deletions vortex-array/src/array/haystack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use crate::arrays::decimal::converted_buffer;
use crate::arrays::primitive::PrimitiveArrayExt;
use crate::arrays::varbinview::BinaryView;
use crate::dtype::DType;
use crate::dtype::DecimalType;
use crate::dtype::NativeDecimalType;
use crate::dtype::NativePType;
use crate::dtype::PType;
Expand Down Expand Up @@ -116,7 +115,7 @@ fn new_state(elements: ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<Box<dyn
})
}
DType::Decimal(decimal, _) => {
let values_type = DecimalType::smallest_decimal_value_type(decimal);
let values_type = decimal.canonical_values_type();
let elements = elements.execute::<DecimalArray>(ctx)?;
let all_valid = Mask::new_true(elements.len());
match_each_decimal_value_type!(values_type, |T| {
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn random_array_chunk(
},
d @ DType::Decimal(decimal, n) => {
let elem_len = chunk_len.unwrap_or(u.int_in_range(0..=20)?);
match_each_decimal_value_type!(DecimalType::smallest_decimal_value_type(decimal), |D| {
match_each_decimal_value_type!(decimal.canonical_values_type(), |D| {
let mut builder = DecimalBuilder::new_in::<D>(
*decimal,
*n,
Expand Down
5 changes: 2 additions & 3 deletions vortex-array/src/arrays/constant/vtable/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use crate::builders::ArrayBuilder;
use crate::builders::VarBinViewBuilder;
use crate::builders::builder_with_capacity_in;
use crate::dtype::DType;
use crate::dtype::DecimalType;
use crate::dtype::Nullability;
use crate::match_each_decimal_value;
use crate::match_each_decimal_value_type;
Expand Down Expand Up @@ -94,7 +93,7 @@ pub(crate) fn constant_canonicalize(
})
}
DType::Decimal(decimal_type, ..) => {
let size = DecimalType::smallest_decimal_value_type(decimal_type);
let size = decimal_type.canonical_values_type();
let decimal = scalar.as_decimal();
let Some(value) = decimal.decimal_value() else {
let all_null = match_each_decimal_value_type!(size, |D| {
Expand Down Expand Up @@ -353,7 +352,7 @@ fn flat_elements(
.into_array()
}),
DType::Decimal(decimal, nullability) => {
let values_type = DecimalType::smallest_decimal_value_type(decimal);
let values_type = decimal.canonical_values_type();
match_each_decimal_value_type!(values_type, |T| {
let mut buffer =
BufferMut::<T>::with_capacity_in(elements.len(), allocator.clone());
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/arrays/decimal/compute/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl CastKernel for Decimal {
ConstantArray::new(Scalar::null(dtype.clone()), array.len()).into_array(),
));
}
let target_values_type = DecimalType::smallest_decimal_value_type(to_decimal_dtype);
let target_values_type = to_decimal_dtype.canonical_values_type();

match_each_decimal_value_type!(array.values_type(), |F| {
match_each_decimal_value_type!(target_values_type, |T| {
Expand Down
Loading
Loading