comphead commented on code in PR #14683:
URL: https://github.com/apache/datafusion/pull/14683#discussion_r1957389450
##########
datafusion/common/src/lib.rs:
##########
@@ -104,21 +104,72 @@ pub type HashSet<T, S = DefaultHashBuilder> =
hashbrown::HashSet<T, S>;
#[macro_export]
macro_rules! downcast_value {
($Value: expr, $Type: ident) => {{
- use std::any::type_name;
- $Value.as_any().downcast_ref::<$Type>().ok_or_else(|| {
- DataFusionError::Internal(format!(
- "could not cast value to {}",
- type_name::<$Type>()
- ))
- })?
+ use $crate::__private::DowncastArrayHelper;
+ $Value.downcast_array_helper::<$Type>()?
}};
($Value: expr, $Type: ident, $T: tt) => {{
- use std::any::type_name;
- $Value.as_any().downcast_ref::<$Type<$T>>().ok_or_else(|| {
- DataFusionError::Internal(format!(
- "could not cast value to {}",
- type_name::<$Type<$T>>()
- ))
- })?
+ use $crate::__private::DowncastArrayHelper;
+ $Value.downcast_array_helper::<$Type<$T>>()?
}};
}
+
+// Not public API.
+#[doc(hidden)]
+pub mod __private {
+ use super::DataFusionError;
+ use super::Result;
+ use arrow::array::Array;
+ use std::any::{type_name, Any};
+
+ #[doc(hidden)]
+ pub trait DowncastArrayHelper {
+ fn downcast_array_helper<U: Any>(&self) -> Result<&U>;
+ }
+
+ impl<T: Array + ?Sized> DowncastArrayHelper for T {
+ fn downcast_array_helper<U: Any>(&self) -> Result<&U> {
+ self.as_any().downcast_ref().ok_or_else(|| {
+ DataFusionError::Internal(format!(
Review Comment:
```suggestion
internal_datafusion_err!(
```
to provide backtraces
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]