alamb commented on issue #6162:
URL: https://github.com/apache/arrow-rs/issues/6162#issuecomment-2263988067

   BTW I had a hacky version in datafusion 
https://github.com/apache/datafusion/pull/11723: 
https://github.com/apache/datafusion/pull/11723/files#diff-07b427ee25e195566e30cca0e77e5eb4c63c54ea74f6ea15914fdd7a5a889186R169
   
   In case that helps
   
   ```rust
   
   // Workaround arrow-rs bug in can_cast_types
   // External error: query failed: DataFusion error: Arrow error: Cast error: 
Casting from BinaryView to Utf8 not supported
   fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
       arrow::compute::can_cast_types(from_type, to_type)
           || matches!(
               (from_type, to_type),
               (DataType::BinaryView, DataType::Utf8 | DataType::LargeUtf8)
                   | (DataType::Utf8 | DataType::LargeUtf8, 
DataType::BinaryView)
           )
   }
   
   // Work around arrow-rs casting bug
   // External error: query failed: DataFusion error: Arrow error: Cast error: 
Casting from BinaryView to Utf8 not supported
   fn cast(array: &dyn Array, to_type: &DataType) -> Result<ArrayRef, 
ArrowError> {
       match (array.data_type(), to_type) {
           (DataType::BinaryView, DataType::Utf8) => {
               let array = array.as_binary_view();
               let mut builder = StringBuilder::with_capacity(array.len(), 8 * 
1024);
               for value in array.iter() {
                   // check if the value is valid utf8 (should do this once, 
not each value)
                   let value = value.map(|value| 
std::str::from_utf8(value)).transpose()?;
   
                   builder.append_option(value);
               }
   
               Ok(Arc::new(builder.finish()))
           }
           // fallback to arrow kernel
           (_, _) => arrow::compute::cast(array, to_type),
       }
   }
   ```


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