alamb opened a new issue #876:
URL: https://github.com/apache/arrow-rs/issues/876


   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   I want to cast a null constant in DataFusion to an array (so the expression 
evaluation logic is general). Sometimes this requires casting. 
   
   While this type of casting is definitely a corner case, it is required for 
completeness and will unify our handling of null constants in DataFusion
   
   **Describe the solution you'd like**
   I want the cast kernel to support casting to/from NullArray for all data 
types
   
   Using `Int8` as example, I want this code to work
   ```rust
       // should be able to cast Int8Array to Null array
       let input: ArrayRef = Arc::new(vec![Some(1), Some(2), 
None].into_iter().collect::<Int8Array>());
       let cast = arrow::compute::cast(&input, &DataType::Null).expect("should 
work");
   
       let expected = new_null_array(&DataType::Null, 3);
       assert_eq!(&cast, &expected);
   ```
   
   Today it errors with:
   ```
   thread 'main' panicked at 'should work: CastError("Casting from Int8 to Null 
not supported")', src/main.rs:15:62
   ```
   
   And also I want to cast from `Null` to `Int8`:
   
   ```rust
       // Likewise, should be able to cast NullArray to Int8Array
       let input = new_null_array(&DataType::Null, 3);
       let cast = arrow::compute::cast(&input, &DataType::Int8).expect("should 
work");
       let expected = new_null_array(&DataType::Int8, 3);
       assert_eq!(&cast, &expected);
   
       // which is equivalent to
       let expected: ArrayRef = Arc::new(vec![None, None, 
None].into_iter().collect::<Int8Array>());
       assert_eq!(&cast, &expected);
   ```
   
   Which errors like this:
   ```
   thread 'main' panicked at 'should work: CastError("Casting from Null to Int8 
not supported")', src/main.rs:26:62
   ```
   
   
   
   **Describe alternatives you've considered**
   N/A 
   **Additional context**
   See https://github.com/apache/arrow-datafusion/issues/1179 and 
https://github.com/apache/arrow-datafusion/issues/1184


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