Skip to content

Commit

Permalink
Don't validate decimal precision in ArrayData (apache#2637)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Oct 14, 2022
1 parent d67d5fb commit c92945c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
19 changes: 0 additions & 19 deletions arrow-data/src/data.rs
Expand Up @@ -18,9 +18,6 @@
//! Contains `ArrayData`, a generic representation of Arrow array data which encapsulates
//! common attributes and operations for Arrow array.

use crate::decimal::{
validate_decimal256_precision_with_lt_bytes, validate_decimal_precision,
};
use crate::{bit_iterator::BitSliceIterator, bitmap::Bitmap};
use arrow_buffer::{bit_util, ArrowNativeType, Buffer, MutableBuffer};
use arrow_schema::{ArrowError, DataType, IntervalUnit, UnionMode};
Expand Down Expand Up @@ -1004,22 +1001,6 @@ impl ArrayData {

pub fn validate_values(&self) -> Result<(), ArrowError> {
match &self.data_type {
DataType::Decimal128(p, _) => {
let values_buffer: &[i128] = self.typed_buffer(0, self.len)?;
for value in values_buffer {
validate_decimal_precision(*value, *p)?;
}
Ok(())
}
DataType::Decimal256(p, _) => {
let values = self.buffers()[0].as_slice();
for pos in 0..self.len() {
let offset = pos * 32;
let raw_bytes = &values[offset..offset + 32];
validate_decimal256_precision_with_lt_bytes(raw_bytes, *p)?;
}
Ok(())
}
DataType::Utf8 => self.validate_utf8::<i32>(),
DataType::LargeUtf8 => self.validate_utf8::<i64>(),
DataType::Binary => self.validate_offsets_full::<i32>(self.buffers[1].len()),
Expand Down
9 changes: 6 additions & 3 deletions arrow/tests/array_validation.rs
Expand Up @@ -25,6 +25,7 @@ use arrow_data::ArrayData;
use arrow_schema::{DataType, Field, UnionMode};
use std::ptr::NonNull;
use std::sync::Arc;
use arrow_array::Decimal128Array;

#[test]
#[should_panic(
Expand Down Expand Up @@ -1038,7 +1039,6 @@ fn test_string_data_from_foreign() {
}

#[test]
#[cfg(not(feature = "force_validate"))]
fn test_decimal_full_validation() {
let values_builder = UInt8Builder::with_capacity(10);
let byte_width = 16;
Expand All @@ -1055,8 +1055,11 @@ fn test_decimal_full_validation() {
.len(fixed_size_array.len())
.add_buffer(fixed_size_array.data_ref().child_data()[0].buffers()[0].clone());
let array_data = unsafe { builder.build_unchecked() };
let validation_result = array_data.validate_full();
let error = validation_result.unwrap_err();
array_data.validate_full().unwrap();

let array = Decimal128Array::from(array_data);
let error = array.validate_decimal_precision(array.precision()).unwrap_err();

assert_eq!(
"Invalid argument error: 123456 is too large to store in a Decimal128 of precision 5. Max is 99999",
error.to_string()
Expand Down

0 comments on commit c92945c

Please sign in to comment.