You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/02 11:04:32 UTC

[GitHub] [arrow-rs] alamb commented on a diff in pull request #1767: Remove `validate_decimal_precision` check in `DecimalBuilder.append_value`

alamb commented on code in PR #1767:
URL: https://github.com/apache/arrow-rs/pull/1767#discussion_r887825142


##########
arrow/src/array/data.rs:
##########
@@ -999,6 +999,27 @@ impl ArrayData {
 
     pub fn validate_dictionary_offset(&self) -> Result<()> {
         match &self.data_type {
+            DataType::Decimal(p, _) => {
+                let values_buffer = &self.buffers[0];
+
+                for pos in 0..values_buffer.len() {
+                    let raw_val = unsafe {
+                        std::slice::from_raw_parts(
+                            values_buffer.as_ptr().add(pos),
+                            16_usize,
+                        )
+                    };
+                    let as_array = raw_val.try_into();
+                    match as_array {
+                        Ok(v) if raw_val.len() == 16 => {

Review Comment:
   For some reason this code seems overly complicated -- I wonder if you could call i128::from_le_bytes directly on a slice like 
   
   ```rust
   for pos in 0..values_buffer.len() {
     let v = value_buffer.data[pos..pos+16];
     let value = i128::from_le_bytes(v)
   }
   ```
   
   or something 🤔 



##########
arrow/src/array/data.rs:
##########
@@ -999,6 +999,27 @@ impl ArrayData {
 
     pub fn validate_dictionary_offset(&self) -> Result<()> {
         match &self.data_type {
+            DataType::Decimal(p, _) => {

Review Comment:
   I agree this code is necessary in `validate` 👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org