neilconway opened a new issue, #10866:
URL: https://github.com/apache/arrow-rs/issues/10866

   ### Describe the bug
   
   As discussed in #2387, validating that a decimal value fits within the 
declared precision is opt-in; i.e., decimal values that exceed their type's 
declared precision is allowed. When such values are displayed/formatted (e.g., 
via `value_as_string`), there is incorrect behavior: either an incorrect value 
is produced or a panic occurs.
   
   ### To Reproduce
   
   ```rust
   use arrow_array::Decimal128Array;
   use arrow_schema::DataType;
   
   // 1234.5 declared as Decimal128(3, 1)
   let a = Decimal128Array::from(vec![12345])
       .with_precision_and_scale(3, 1)
       .unwrap();
   a.value_as_string(0); // "12.3" — expected "1234.5"
   
   // 12.345 declared as Decimal128(3, 3)
   let a = Decimal128Array::from(vec![12345])
       .with_precision_and_scale(3, 3)
       .unwrap();
   a.value_as_string(0); // ".123" — expected "12.345"
   
   // 1.2345 declared as Decimal128(2, 4)
   let a = 
Decimal128Array::from(vec![12345]).with_data_type(DataType::Decimal128(2, 4));
   a.value_as_string(0);
   ```
   
   ### Expected behavior
   
   The decimal value should be displayed correctly (i.e., the declared 
precision should effectively be ignored for display purposes).
   
   We could in principle produce an error instead of displaying such values, 
but this is difficult for practical purposes (e.g., related APIs don't return 
`Result` or a similar channel for surfacing errors), and would be inconsistent 
with Arrow behavior elsewhere.
   
   ### Additional context
   
   _No response_


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to