-
Notifications
You must be signed in to change notification settings - Fork 867
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
RFC: Simplify decimal (#2440) #2477
Changes from 1 commit
4d3ed30
559f7c1
b151c14
f4db98f
2917bd7
dfa9092
02d120c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,12 @@ | |
// under the License. | ||
|
||
use crate::array::array::ArrayAccessor; | ||
use crate::array::BasicDecimalArray; | ||
use crate::array::DecimalArray; | ||
use crate::datatypes::{Decimal128Type, Decimal256Type}; | ||
|
||
use super::{ | ||
Array, BooleanArray, Decimal128Array, GenericBinaryArray, GenericListArray, | ||
GenericStringArray, PrimitiveArray, | ||
BooleanArray, GenericBinaryArray, GenericListArray, GenericStringArray, | ||
PrimitiveArray, | ||
}; | ||
|
||
/// an iterator that returns Some(T) or None, that can be used on any [`ArrayAccessor`] | ||
|
@@ -104,69 +105,14 @@ pub type GenericStringIter<'a, T> = ArrayIter<&'a GenericStringArray<T>>; | |
pub type GenericBinaryIter<'a, T> = ArrayIter<&'a GenericBinaryArray<T>>; | ||
pub type GenericListArrayIter<'a, O> = ArrayIter<&'a GenericListArray<O>>; | ||
|
||
pub type BasicDecimalIter<'a, const BYTE_WIDTH: usize> = | ||
ArrayIter<&'a BasicDecimalArray<BYTE_WIDTH>>; | ||
pub type DecimalIter<'a, T> = ArrayIter<&'a DecimalArray<T>>; | ||
/// an iterator that returns `Some(Decimal128)` or `None`, that can be used on a | ||
/// [`Decimal128Array`] | ||
pub type Decimal128Iter<'a> = BasicDecimalIter<'a, 16>; | ||
pub type Decimal128Iter<'a> = DecimalIter<'a, Decimal128Type>; | ||
|
||
/// an iterator that returns `Some(Decimal256)` or `None`, that can be used on a | ||
/// [`super::Decimal256Array`] | ||
pub type Decimal256Iter<'a> = BasicDecimalIter<'a, 32>; | ||
/// an iterator that returns `Some(i128)` or `None`, that can be used on a | ||
/// [`Decimal128Array`] | ||
#[derive(Debug)] | ||
#[deprecated(note = "Please use `Decimal128Iter` instead. \ | ||
`DecimalIter` iterates `Decimal128` values as i128 values. \ | ||
This is kept mostly for back-compatibility purpose. Suggests to use `Decimal128Array.iter()` \ | ||
that returns `Decimal128Iter`.")] | ||
pub struct DecimalIter<'a> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to reuse this name, as |
||
array: &'a Decimal128Array, | ||
current: usize, | ||
current_end: usize, | ||
} | ||
|
||
#[allow(deprecated)] | ||
impl<'a> DecimalIter<'a> { | ||
pub fn new(array: &'a Decimal128Array) -> Self { | ||
Self { | ||
array, | ||
current: 0, | ||
current_end: array.len(), | ||
} | ||
} | ||
} | ||
|
||
#[allow(deprecated)] | ||
impl<'a> std::iter::Iterator for DecimalIter<'a> { | ||
type Item = Option<i128>; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
if self.current == self.current_end { | ||
None | ||
} else { | ||
let old = self.current; | ||
self.current += 1; | ||
// TODO: Improve performance by avoiding bounds check here | ||
// (by using adding a `value_unchecked, for example) | ||
if self.array.is_null(old) { | ||
Some(None) | ||
} else { | ||
Some(Some(self.array.value(old).as_i128())) | ||
} | ||
} | ||
} | ||
|
||
#[inline] | ||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
let remain = self.current_end - self.current; | ||
(remain, Some(remain)) | ||
} | ||
} | ||
|
||
/// iterator has known size. | ||
#[allow(deprecated)] | ||
impl<'a> std::iter::ExactSizeIterator for DecimalIter<'a> {} | ||
pub type Decimal256Iter<'a> = DecimalIter<'a, Decimal256Type>; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,15 +199,12 @@ pub(crate) use self::data::BufferSpec; | |
pub use self::array_binary::BinaryArray; | ||
pub use self::array_binary::LargeBinaryArray; | ||
pub use self::array_boolean::BooleanArray; | ||
pub use self::array_decimal::BasicDecimalArray; | ||
pub use self::array_decimal::Decimal128Array; | ||
pub use self::array_decimal::Decimal256Array; | ||
pub use self::array_decimal::DecimalArray; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is the generic representation of the array, akin to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
pub use self::array_fixed_size_binary::FixedSizeBinaryArray; | ||
pub use self::array_fixed_size_list::FixedSizeListArray; | ||
|
||
#[deprecated(note = "Please use `Decimal128Array` instead")] | ||
pub type DecimalArray = Decimal128Array; | ||
|
||
pub use self::array_dictionary::{DictionaryArray, TypedDictionaryArray}; | ||
pub use self::array_list::LargeListArray; | ||
pub use self::array_list::ListArray; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is certainly a more consistent with the other Array types