Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Nov 9, 2022
1 parent 6f9a520 commit 3e6d2bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ impl<T: DecimalType + ArrowPrimitiveType> PrimitiveArray<T> {
/// 2. `scale` is larger than `T::MAX_SCALE`
/// 3. `scale` is > `precision`
pub fn with_precision_and_scale(
self,
&self,
precision: u8,
scale: u8,
) -> Result<Self, ArrowError>
Expand Down
44 changes: 15 additions & 29 deletions arrow/src/row/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ use std::sync::Arc;

use arrow_array::cast::*;
use arrow_array::*;
use arrow_buffer::i256;

use crate::compute::SortOptions;
use crate::datatypes::*;
Expand Down Expand Up @@ -504,8 +503,6 @@ fn new_empty_rows(
array => lengths.iter_mut().for_each(|x| *x += fixed::encoded_len(array)),
DataType::Null => {},
DataType::Boolean => lengths.iter_mut().for_each(|x| *x += bool::ENCODED_LEN),
DataType::Decimal128(_, _) => lengths.iter_mut().for_each(|x| *x += i128::ENCODED_LEN),
DataType::Decimal256(_, _) => lengths.iter_mut().for_each(|x| *x += i256::ENCODED_LEN),
DataType::Binary => as_generic_binary_array::<i32>(array)
.iter()
.zip(lengths.iter_mut())
Expand Down Expand Up @@ -586,22 +583,6 @@ fn encode_column(
column => fixed::encode(out, column, opts),
DataType::Null => {}
DataType::Boolean => fixed::encode(out, as_boolean_array(column), opts),
DataType::Decimal128(_, _) => {
let column = column
.as_any()
.downcast_ref::<Decimal128Array>()
.unwrap();

fixed::encode(out, column, opts)
},
DataType::Decimal256(_, _) => {
let column = column
.as_any()
.downcast_ref::<Decimal256Array>()
.unwrap();

fixed::encode(out, column, opts)
},
DataType::Binary => {
variable::encode(out, as_generic_binary_array::<i32>(column).iter(), opts)
}
Expand Down Expand Up @@ -653,16 +634,6 @@ unsafe fn decode_column(
DataType::LargeBinary => Arc::new(decode_binary::<i64>(rows, options)),
DataType::Utf8 => Arc::new(decode_string::<i32>(rows, options)),
DataType::LargeUtf8 => Arc::new(decode_string::<i64>(rows, options)),
DataType::Decimal128(p, s) => Arc::new(
decode_primitive::<Decimal128Type>(rows, options)
.with_precision_and_scale(*p, *s)
.unwrap(),
),
DataType::Decimal256(p, s) => Arc::new(
decode_primitive::<Decimal256Type>(rows, options)
.with_precision_and_scale(*p, *s)
.unwrap(),
),
DataType::Dictionary(k, v) => match k.as_ref() {
DataType::Int8 => Arc::new(decode_dictionary::<Int8Type>(
interner.unwrap(),
Expand Down Expand Up @@ -726,6 +697,21 @@ unsafe fn decode_column(
)))
}
};
let array: ArrayRef = match &field.data_type {
DataType::Decimal128(p, s) => {
let d = as_primitive_array::<Decimal128Type>(&array)
.with_precision_and_scale(*p, *s)
.unwrap();
Arc::new(d)
}
DataType::Decimal256(p, s) => {
let d = as_primitive_array::<Decimal256Type>(&array)
.with_precision_and_scale(*p, *s)
.unwrap();
Arc::new(d)
}
_ => array,
};
Ok(array)
}

Expand Down

0 comments on commit 3e6d2bb

Please sign in to comment.