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

   **Describe the bug**
   <!--
   A clear and concise description of what the bug is.
   -->
   Casting a `StringArray` to `Decimal256Array` with 0 doesn't work if the 
decimal type is (1, 0) or (2, 0)
   **To Reproduce**
   <!--
   Steps to reproduce the behavior:
   -->
   ```rust
   use arrow::array::{Array, Decimal256Array, StringArray};
   use arrow::compute::{cast_with_options, CastOptions};
   use arrow::datatypes::{DataType, Field, Schema};
   use arrow::record_batch::RecordBatch;
   use arrow::util::display::FormatOptions;
   use std::sync::Arc;
   
   fn main() {
       // Create a StringArray with "0" as the only element
       let string_values = vec![Some("0")];
       let string_array = StringArray::from(string_values);
   
       // Define the schema for the record batch
       let schema = Arc::new(Schema::new(vec![Field::new("string", 
DataType::Utf8, false)]));
   
       // Create a record batch
       let record_batch = RecordBatch::try_new(schema, 
vec![Arc::new(string_array)]).unwrap();
   
       // Define the target type (Decimal256 with precision and scale)
       let decimal_type = DataType::Decimal256(1, 0);
   
       // Cast the StringArray to Decimal256Array
       let casted_array = cast_with_options(&record_batch.column(0), 
&decimal_type, &CastOptions {
           safe: false,
           format_options: FormatOptions::new(),
       },).unwrap();
   
       // Downcast the casted array to Decimal256Array
       let decimal_array = casted_array
           .as_any()
           .downcast_ref::<Decimal256Array>()
           .unwrap();
   
       // Print the result
       for i in 0..decimal_array.len() {
           println!("{}", decimal_array.value(i));
       }
   }
   
   ```
   **Expected behavior**
   <!--
   A clear and concise description of what you expected to happen.
   -->
   0
   **Additional context**
   <!--
   Add any other context about the problem here.
   -->


-- 
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