alamb opened a new pull request #1223:
URL: https://github.com/apache/arrow-rs/pull/1223


   # Which issue does this PR close?
   
   Closes https://github.com/apache/arrow-rs/issues/1009
   
   Closes https://github.com/apache/arrow-rs/issues/1083
   
   
   # Rationale for this change
    
   It is somewhat awkward to create `DecimalArray` as well as iterate through 
their values.
   
   This leads to (repeated) code like `create_decimal_array` 
https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/apache/arrow-rs%24+create_decimal_array&patternType=literal
   
   ```rust
       fn create_decimal_array(
           array: &[Option<i128>],
           precision: usize,
           scale: usize,
       ) -> DecimalArray {
           let mut decimal_builder = DecimalBuilder::new(array.len(), 
precision, scale);
           for value in array {
               match value {
                   None => {
                       decimal_builder.append_null().unwrap();
                   }
                   Some(v) => {
                       decimal_builder.append_value(*v).unwrap();
                   }
               }
           }
           decimal_builder.finish()
       }
   ```
   
   (there is similar repetition in datafusion)
   
   # What changes are included in this PR?
   
   1. Add `DecimalArray::from` and `DecimalArray::from_iter_values` (mirroring 
`PrimitiveArray`)
   2. Add `DecimalArray::into_iter()` and `DecimalArray::iter()` for iterating 
through values
   3. Add `DecimalArray::with_precision_and_scale()` for changing the relevant 
precision and scale
   2. Add documentation
   3. Refactor some existing code to show how the new APIs can be used
   
   # Are there any user-facing changes?
   1. Nicer APIs for creating and working with `DecimalArray`s
   
   


-- 
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-unsubscr...@arrow.apache.org

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


Reply via email to