diff --git a/arrow/src/array/array_decimal.rs b/arrow/src/array/array_decimal.rs index 915bf8d07c06..3fe490a46b72 100644 --- a/arrow/src/array/array_decimal.rs +++ b/arrow/src/array/array_decimal.rs @@ -94,6 +94,7 @@ pub trait BasicDecimalArray>: private_decimal::DecimalArrayPrivate { const VALUE_LENGTH: i32; + const DEFAULT_TYPE: DataType; fn data(&self) -> &ArrayData; @@ -225,17 +226,14 @@ pub trait BasicDecimalArray>: /// The default precision and scale used when not specified. fn default_type() -> DataType { - // Keep maximum precision - if Self::VALUE_LENGTH == 16 { - DataType::Decimal128(DECIMAL128_MAX_PRECISION, DECIMAL_DEFAULT_SCALE) - } else { - DataType::Decimal256(DECIMAL256_MAX_PRECISION, DECIMAL_DEFAULT_SCALE) - } + Self::DEFAULT_TYPE } } impl BasicDecimalArray for Decimal128Array { const VALUE_LENGTH: i32 = 16; + const DEFAULT_TYPE: DataType = + DataType::Decimal128(DECIMAL128_MAX_PRECISION, DECIMAL_DEFAULT_SCALE); fn data(&self) -> &ArrayData { &self.data @@ -252,6 +250,8 @@ impl BasicDecimalArray for Decimal128Array { impl BasicDecimalArray for Decimal256Array { const VALUE_LENGTH: i32 = 32; + const DEFAULT_TYPE: DataType = + DataType::Decimal256(DECIMAL256_MAX_PRECISION, DECIMAL_DEFAULT_SCALE); fn data(&self) -> &ArrayData { &self.data @@ -428,7 +428,7 @@ impl> FromIterator> for Decimal256Array { let mut null_buf = BooleanBufferBuilder::new(size_hint); - let mut buffer = MutableBuffer::from_len_zeroed(0); + let mut buffer = MutableBuffer::with_capacity(size_hint); iter.for_each(|item| { if let Some(a) = item {