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


   Draft as it builds on https://github.com/apache/arrow-rs/pull/1263
   
   # Which issue does this PR close?
   
   Closes https://github.com/apache/arrow-rs/issues/1299
   
   # Rationale for this change
    
   Inspired by the challenge writing tests on 
https://github.com/apache/arrow-rs/pull/1263 from @viirya
   
   Otherwise known as "no one should have to write the following to work with 
`DictionaryArrays`":
   
   <details>
     <summary>Click to expand!</summary>
     
   
   ```rust
     fn get_dict_arraydata(
           keys: Buffer,
           key_type: DataType,
           value_data: ArrayData,
       ) -> ArrayData {
           let value_type = value_data.data_type().clone();
           let dict_data_type =
               DataType::Dictionary(Box::new(key_type), Box::new(value_type));
           ArrayData::builder(dict_data_type)
               .len(3)
               .add_buffer(keys)
               .add_child_data(value_data)
               .build()
               .unwrap()
       }
   
       #[test]
       fn test_eq_dyn_dictionary_i8_array() {
           let key_type = DataType::Int8;
           // Construct a value array
           let value_data = ArrayData::builder(DataType::Int8)
               .len(8)
               .add_buffer(Buffer::from(
                   &[10_i8, 11, 12, 13, 14, 15, 16, 17].to_byte_slice(),
               ))
               .build()
               .unwrap();
   
           let keys1 = Buffer::from(&[2_i8, 3, 4].to_byte_slice());
           let keys2 = Buffer::from(&[2_i8, 4, 4].to_byte_slice());
           let dict_array1: DictionaryArray<Int8Type> = 
Int8DictionaryArray::from(
               get_dict_arraydata(keys1, key_type.clone(), value_data.clone()),
           );
           let dict_array2: DictionaryArray<Int8Type> =
               Int8DictionaryArray::from(get_dict_arraydata(keys2, key_type, 
value_data));
   
           let result = eq_dyn(&dict_array1, &dict_array2);
           assert!(result.is_ok());
           assert_eq!(result.unwrap(), BooleanArray::from(vec![true, false, 
true]));
       }
   ```
   </details>
   
   # What changes are included in this PR?
   
   1. Add `DictionaryArray::try_new()` function
   2. Tests
   2. Doc tests
   3. Update tests from https://github.com/apache/arrow-rs/pull/1263 to use the 
new API
   
   
   
   <!---
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking 
change` label.
   -->
   


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