This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 14a85fa383 chore: remove as_any from aggregate and window functions
(#21209)
14a85fa383 is described below
commit 14a85fa3838951f957f81a6a2936694a1bfeeef1
Author: Tim Saucer <[email protected]>
AuthorDate: Mon Mar 30 16:20:39 2026 -0400
chore: remove as_any from aggregate and window functions (#21209)
## Which issue does this PR close?
This is a follow on to https://github.com/apache/datafusion/pull/20812
but treats aggregate and window functions.
## Rationale for this change
This PR reduces the amount of boilerplate code that users need to write
for aggregate and window functions.
## What changes are included in this PR?
Now that we have [trait
upcasting](https://blog.rust-lang.org/2025/04/03/Rust-1.86.0/) since
rust 1.86, we no longer need every implementation of these functions to
have the as_any function that returns &self. This PR makes Any an
supertrait and makes the appropriate casts when necessary.
## Are these changes tested?
Existing unit tests.
## Are there any user-facing changes?
Yes, the users simply need to remove the `as_any` function. The upgrade
guide is updated.
---------
Co-authored-by: Andrew Lamb <[email protected]>
---
datafusion-examples/examples/udf/advanced_udaf.rs | 11 +-----
datafusion-examples/examples/udf/advanced_udwf.rs | 11 +-----
.../tests/user_defined/user_defined_aggregates.rs | 9 -----
.../user_defined/user_defined_window_functions.rs | 13 -------
datafusion/expr/src/expr_fn.rs | 9 -----
datafusion/expr/src/test/function_stub.rs | 22 -----------
datafusion/expr/src/udaf.rs | 21 ++--------
datafusion/expr/src/udf_eq.rs | 4 +-
datafusion/expr/src/udwf.rs | 22 ++---------
.../ffi/src/proto/logical_extension_codec.rs | 4 +-
.../ffi/src/proto/physical_extension_codec.rs | 8 ++--
datafusion/ffi/src/udaf/mod.rs | 22 +++++------
datafusion/ffi/src/udwf/mod.rs | 14 +++----
.../functions-aggregate/src/approx_distinct.rs | 5 ---
.../functions-aggregate/src/approx_median.rs | 5 ---
.../src/approx_percentile_cont.rs | 5 ---
.../src/approx_percentile_cont_with_weight.rs | 5 ---
datafusion/functions-aggregate/src/array_agg.rs | 4 --
datafusion/functions-aggregate/src/average.rs | 5 ---
.../functions-aggregate/src/bit_and_or_xor.rs | 5 ---
datafusion/functions-aggregate/src/bool_and_or.rs | 9 -----
datafusion/functions-aggregate/src/correlation.rs | 6 ---
datafusion/functions-aggregate/src/count.rs | 4 --
datafusion/functions-aggregate/src/covariance.rs | 8 ----
datafusion/functions-aggregate/src/first_last.rs | 9 -----
datafusion/functions-aggregate/src/grouping.rs | 6 ---
datafusion/functions-aggregate/src/median.rs | 4 --
datafusion/functions-aggregate/src/min_max.rs | 8 ----
datafusion/functions-aggregate/src/nth_value.rs | 5 ---
.../functions-aggregate/src/percentile_cont.rs | 4 --
datafusion/functions-aggregate/src/regr.rs | 5 ---
datafusion/functions-aggregate/src/stddev.rs | 11 ------
datafusion/functions-aggregate/src/string_agg.rs | 5 ---
datafusion/functions-aggregate/src/sum.rs | 5 ---
datafusion/functions-aggregate/src/variance.rs | 8 ----
datafusion/functions-window/src/cume_dist.rs | 6 ---
datafusion/functions-window/src/lead_lag.rs | 5 ---
datafusion/functions-window/src/macros.rs | 28 --------------
datafusion/functions-window/src/nth_value.rs | 5 ---
datafusion/functions-window/src/ntile.rs | 5 ---
datafusion/functions-window/src/rank.rs | 5 ---
datafusion/functions-window/src/row_number.rs | 5 ---
.../src/simplify_expressions/expr_simplifier.rs | 8 ----
datafusion/physical-expr/src/aggregate.rs | 4 --
datafusion/proto/tests/cases/mod.rs | 9 -----
.../proto/tests/cases/roundtrip_logical_plan.rs | 8 ++--
.../proto/tests/cases/roundtrip_physical_plan.rs | 5 ++-
datafusion/spark/src/function/aggregate/avg.rs | 6 +--
datafusion/spark/src/function/aggregate/collect.rs | 10 +----
datafusion/spark/src/function/aggregate/try_sum.rs | 5 ---
docs/source/library-user-guide/upgrading/54.0.0.md | 45 +++++++++++++++++++---
51 files changed, 79 insertions(+), 381 deletions(-)
diff --git a/datafusion-examples/examples/udf/advanced_udaf.rs
b/datafusion-examples/examples/udf/advanced_udaf.rs
index 89f621d30e..f1651dbf28 100644
--- a/datafusion-examples/examples/udf/advanced_udaf.rs
+++ b/datafusion-examples/examples/udf/advanced_udaf.rs
@@ -20,7 +20,7 @@
use arrow::datatypes::{Field, Schema};
use datafusion::physical_expr::NullState;
use datafusion::{arrow::datatypes::DataType, logical_expr::Volatility};
-use std::{any::Any, sync::Arc};
+use std::sync::Arc;
use arrow::array::{
ArrayRef, AsArray, Float32Array, PrimitiveArray, PrimitiveBuilder,
UInt32Array,
@@ -64,11 +64,6 @@ impl GeoMeanUdaf {
}
impl AggregateUDFImpl for GeoMeanUdaf {
- /// We implement as_any so that we can downcast the AggregateUDFImpl trait
object
- fn as_any(&self) -> &dyn Any {
- self
- }
-
/// Return the name of this function
fn name(&self) -> &str {
"geo_mean"
@@ -387,10 +382,6 @@ impl SimplifiedGeoMeanUdaf {
}
impl AggregateUDFImpl for SimplifiedGeoMeanUdaf {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"simplified_geo_mean"
}
diff --git a/datafusion-examples/examples/udf/advanced_udwf.rs
b/datafusion-examples/examples/udf/advanced_udwf.rs
index 615d099c28..2508e6cd60 100644
--- a/datafusion-examples/examples/udf/advanced_udwf.rs
+++ b/datafusion-examples/examples/udf/advanced_udwf.rs
@@ -17,7 +17,7 @@
//! See `main.rs` for how to run it.
-use std::{any::Any, sync::Arc};
+use std::sync::Arc;
use arrow::datatypes::Field;
use arrow::{
@@ -68,11 +68,6 @@ impl SmoothItUdf {
}
impl WindowUDFImpl for SmoothItUdf {
- /// We implement as_any so that we can downcast the WindowUDFImpl trait
object
- fn as_any(&self) -> &dyn Any {
- self
- }
-
/// Return the name of this function
fn name(&self) -> &str {
"smooth_it"
@@ -176,10 +171,6 @@ impl SimplifySmoothItUdf {
}
}
impl WindowUDFImpl for SimplifySmoothItUdf {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"simplify_smooth_it"
}
diff --git a/datafusion/core/tests/user_defined/user_defined_aggregates.rs
b/datafusion/core/tests/user_defined/user_defined_aggregates.rs
index e7bd224139..7d22c5df70 100644
--- a/datafusion/core/tests/user_defined/user_defined_aggregates.rs
+++ b/datafusion/core/tests/user_defined/user_defined_aggregates.rs
@@ -18,7 +18,6 @@
//! This module contains end to end demonstrations of creating
//! user defined aggregate functions
-use std::any::Any;
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::mem::{size_of, size_of_val};
@@ -793,10 +792,6 @@ struct TestGroupsAccumulator {
}
impl AggregateUDFImpl for TestGroupsAccumulator {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"geo_mean"
}
@@ -936,10 +931,6 @@ impl MetadataBasedAggregateUdf {
}
impl AggregateUDFImpl for MetadataBasedAggregateUdf {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
&self.name
}
diff --git
a/datafusion/core/tests/user_defined/user_defined_window_functions.rs
b/datafusion/core/tests/user_defined/user_defined_window_functions.rs
index 775325a337..afaf269ca1 100644
--- a/datafusion/core/tests/user_defined/user_defined_window_functions.rs
+++ b/datafusion/core/tests/user_defined/user_defined_window_functions.rs
@@ -44,7 +44,6 @@ use datafusion_physical_expr::{
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::{
- any::Any,
ops::Range,
sync::{
Arc,
@@ -546,10 +545,6 @@ impl OddCounter {
}
impl WindowUDFImpl for SimpleWindowUDF {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"odd_counter"
}
@@ -675,10 +670,6 @@ impl VariadicWindowUDF {
}
impl WindowUDFImpl for VariadicWindowUDF {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"variadic_window_udf"
}
@@ -819,10 +810,6 @@ impl MetadataBasedWindowUdf {
}
impl WindowUDFImpl for MetadataBasedWindowUdf {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
&self.name
}
diff --git a/datafusion/expr/src/expr_fn.rs b/datafusion/expr/src/expr_fn.rs
index 31c209b7f2..ff90180d70 100644
--- a/datafusion/expr/src/expr_fn.rs
+++ b/datafusion/expr/src/expr_fn.rs
@@ -43,7 +43,6 @@ use datafusion_common::{Column, Result, ScalarValue, Spans,
TableReference, plan
use datafusion_functions_window_common::field::WindowUDFFieldArgs;
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
-use std::any::Any;
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;
@@ -588,10 +587,6 @@ impl SimpleAggregateUDF {
}
impl AggregateUDFImpl for SimpleAggregateUDF {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
&self.name
}
@@ -681,10 +676,6 @@ impl SimpleWindowUDF {
}
impl WindowUDFImpl for SimpleWindowUDF {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
&self.name
}
diff --git a/datafusion/expr/src/test/function_stub.rs
b/datafusion/expr/src/test/function_stub.rs
index 26ac16d90d..3be03260a9 100644
--- a/datafusion/expr/src/test/function_stub.rs
+++ b/datafusion/expr/src/test/function_stub.rs
@@ -19,8 +19,6 @@
//!
//! These are used to avoid a dependence on `datafusion-functions-aggregate`
which live in a different crate
-use std::any::Any;
-
use arrow::datatypes::{
DECIMAL32_MAX_PRECISION, DECIMAL32_MAX_SCALE, DECIMAL64_MAX_PRECISION,
DECIMAL64_MAX_SCALE, DECIMAL128_MAX_PRECISION, DECIMAL128_MAX_SCALE,
@@ -113,10 +111,6 @@ impl Default for Sum {
}
impl AggregateUDFImpl for Sum {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"sum"
}
@@ -245,10 +239,6 @@ impl Count {
}
impl AggregateUDFImpl for Count {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"COUNT"
}
@@ -332,10 +322,6 @@ impl Min {
}
impl AggregateUDFImpl for Min {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"min"
}
@@ -414,10 +400,6 @@ impl Max {
}
impl AggregateUDFImpl for Max {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"max"
}
@@ -476,10 +458,6 @@ impl Default for Avg {
}
impl AggregateUDFImpl for Avg {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"avg"
}
diff --git a/datafusion/expr/src/udaf.rs b/datafusion/expr/src/udaf.rs
index 245a80c02c..4659470656 100644
--- a/datafusion/expr/src/udaf.rs
+++ b/datafusion/expr/src/udaf.rs
@@ -84,7 +84,7 @@ pub struct AggregateUDF {
impl PartialEq for AggregateUDF {
fn eq(&self, other: &Self) -> bool {
- self.inner.dyn_eq(other.inner.as_any())
+ self.inner.dyn_eq(other.inner.as_ref() as &dyn Any)
}
}
@@ -415,7 +415,6 @@ where
///
/// /// Implement the AggregateUDFImpl trait for GeoMeanUdf
/// impl AggregateUDFImpl for GeoMeanUdf {
-/// fn as_any(&self) -> &dyn Any { self }
/// fn name(&self) -> &str { "geo_mean" }
/// fn signature(&self) -> &Signature { &self.signature }
/// fn return_type(&self, args: &[DataType]) -> Result<DataType> {
@@ -443,10 +442,7 @@ where
/// // Call the function `geo_mean(col)`
/// let expr = geometric_mean.call(vec![col("a")]);
/// ```
-pub trait AggregateUDFImpl: Debug + DynEq + DynHash + Send + Sync {
- /// Returns this object as an [`Any`] trait object
- fn as_any(&self) -> &dyn Any;
-
+pub trait AggregateUDFImpl: Debug + DynEq + DynHash + Send + Sync + Any {
/// Returns this function's name
fn name(&self) -> &str;
@@ -913,7 +909,7 @@ pub trait AggregateUDFImpl: Debug + DynEq + DynHash + Send
+ Sync {
impl PartialEq for dyn AggregateUDFImpl {
fn eq(&self, other: &Self) -> bool {
- self.dyn_eq(other.as_any())
+ self.dyn_eq(other)
}
}
@@ -1231,10 +1227,6 @@ impl AliasedAggregateUDFImpl {
#[warn(clippy::missing_trait_methods)] // Delegates, so it should implement
every single trait method
impl AggregateUDFImpl for AliasedAggregateUDFImpl {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
self.inner.name()
}
@@ -1415,7 +1407,6 @@ mod test {
use datafusion_functions_aggregate_common::accumulator::{
AccumulatorArgs, StateFieldsArgs,
};
- use std::any::Any;
use std::cmp::Ordering;
use std::hash::{DefaultHasher, Hash, Hasher};
@@ -1437,9 +1428,6 @@ mod test {
}
impl AggregateUDFImpl for AMeanUdf {
- fn as_any(&self) -> &dyn Any {
- self
- }
fn name(&self) -> &str {
"a"
}
@@ -1477,9 +1465,6 @@ mod test {
}
impl AggregateUDFImpl for BMeanUdf {
- fn as_any(&self) -> &dyn Any {
- self
- }
fn name(&self) -> &str {
"b"
}
diff --git a/datafusion/expr/src/udf_eq.rs b/datafusion/expr/src/udf_eq.rs
index b4686384ad..3eed4337ee 100644
--- a/datafusion/expr/src/udf_eq.rs
+++ b/datafusion/expr/src/udf_eq.rs
@@ -96,7 +96,7 @@ impl UdfPointer for Arc<dyn ScalarUDFImpl + '_> {
impl UdfPointer for Arc<dyn AggregateUDFImpl + '_> {
fn equals(&self, other: &(dyn AggregateUDFImpl + '_)) -> bool {
- self.as_ref().dyn_eq(other.as_any())
+ self.as_ref().dyn_eq(other)
}
fn hash_value(&self) -> u64 {
@@ -108,7 +108,7 @@ impl UdfPointer for Arc<dyn AggregateUDFImpl + '_> {
impl UdfPointer for Arc<dyn WindowUDFImpl + '_> {
fn equals(&self, other: &(dyn WindowUDFImpl + '_)) -> bool {
- self.as_ref().dyn_eq(other.as_any())
+ self.as_ref().dyn_eq(other as &dyn Any)
}
fn hash_value(&self) -> u64 {
diff --git a/datafusion/expr/src/udwf.rs b/datafusion/expr/src/udwf.rs
index 7f86a69f87..d2f7f13348 100644
--- a/datafusion/expr/src/udwf.rs
+++ b/datafusion/expr/src/udwf.rs
@@ -82,7 +82,7 @@ impl Display for WindowUDF {
impl PartialEq for WindowUDF {
fn eq(&self, other: &Self) -> bool {
- self.inner.dyn_eq(other.inner.as_any())
+ self.inner.dyn_eq(other.inner.as_ref() as &dyn Any)
}
}
@@ -240,7 +240,6 @@ where
/// [`advanced_udwf.rs`]:
https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/udf/advanced_udwf.rs
/// # Basic Example
/// ```
-/// # use std::any::Any;
/// # use std::sync::LazyLock;
/// # use arrow::datatypes::{DataType, Field, FieldRef};
/// # use datafusion_common::{DataFusionError, plan_err, Result};
@@ -277,7 +276,6 @@ where
///
/// /// Implement the WindowUDFImpl trait for SmoothIt
/// impl WindowUDFImpl for SmoothIt {
-/// fn as_any(&self) -> &dyn Any { self }
/// fn name(&self) -> &str { "smooth_it" }
/// fn signature(&self) -> &Signature { &self.signature }
/// // The actual implementation would smooth the window
@@ -314,10 +312,7 @@ where
/// .build()
/// .unwrap();
/// ```
-pub trait WindowUDFImpl: Debug + DynEq + DynHash + Send + Sync {
- /// Returns this object as an [`Any`] trait object
- fn as_any(&self) -> &dyn Any;
-
+pub trait WindowUDFImpl: Debug + DynEq + DynHash + Send + Sync + Any {
/// Returns this function's name
fn name(&self) -> &str;
@@ -462,7 +457,7 @@ pub enum ReversedUDWF {
impl PartialEq for dyn WindowUDFImpl {
fn eq(&self, other: &Self) -> bool {
- self.dyn_eq(other.as_any())
+ self.dyn_eq(other as &dyn Any)
}
}
@@ -502,10 +497,6 @@ impl AliasedWindowUDFImpl {
#[warn(clippy::missing_trait_methods)] // Delegates, so it should implement
every single trait method
impl WindowUDFImpl for AliasedWindowUDFImpl {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
self.inner.name()
}
@@ -570,7 +561,6 @@ mod test {
use datafusion_functions_window_common::field::WindowUDFFieldArgs;
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
- use std::any::Any;
use std::cmp::Ordering;
use std::hash::{DefaultHasher, Hash, Hasher};
use std::sync::Arc;
@@ -594,9 +584,6 @@ mod test {
/// Implement the WindowUDFImpl trait for AddOne
impl WindowUDFImpl for AWindowUDF {
- fn as_any(&self) -> &dyn Any {
- self
- }
fn name(&self) -> &str {
"a"
}
@@ -637,9 +624,6 @@ mod test {
/// Implement the WindowUDFImpl trait for AddOne
impl WindowUDFImpl for BWindowUDF {
- fn as_any(&self) -> &dyn Any {
- self
- }
fn name(&self) -> &str {
"b"
}
diff --git a/datafusion/ffi/src/proto/logical_extension_codec.rs
b/datafusion/ffi/src/proto/logical_extension_codec.rs
index 99715b576d..19fc73b368 100644
--- a/datafusion/ffi/src/proto/logical_extension_codec.rs
+++ b/datafusion/ffi/src/proto/logical_extension_codec.rs
@@ -680,7 +680,7 @@ mod tests {
let returned_udf = foreign_codec.try_decode_udaf(udf.name(), &bytes)?;
- assert!(returned_udf.inner().as_any().is::<Sum>());
+ assert!((returned_udf.inner().as_ref() as &dyn Any).is::<Sum>());
Ok(())
}
@@ -704,7 +704,7 @@ mod tests {
let returned_udf = foreign_codec.try_decode_udwf(udf.name(), &bytes)?;
- assert!(returned_udf.inner().as_any().is::<Rank>());
+ assert!((returned_udf.inner().as_ref() as &dyn Any).is::<Rank>());
Ok(())
}
diff --git a/datafusion/ffi/src/proto/physical_extension_codec.rs
b/datafusion/ffi/src/proto/physical_extension_codec.rs
index 64effdcd84..ad4a9a0ae7 100644
--- a/datafusion/ffi/src/proto/physical_extension_codec.rs
+++ b/datafusion/ffi/src/proto/physical_extension_codec.rs
@@ -520,7 +520,7 @@ pub(crate) mod tests {
buf.push(Self::MAGIC_NUMBER);
let udf = node.inner();
- let Some(_udf) = udf.as_any().downcast_ref::<Sum>() else {
+ let Some(_udf) = (udf.as_ref() as &dyn Any).downcast_ref::<Sum>()
else {
return exec_err!("TestExtensionCodec only expects Sum UDAF");
};
@@ -550,7 +550,7 @@ pub(crate) mod tests {
buf.push(Self::MAGIC_NUMBER);
let udf = node.inner();
- let Some(udf) = udf.as_any().downcast_ref::<Rank>() else {
+ let Some(udf) = (udf.as_ref() as &dyn Any).downcast_ref::<Rank>()
else {
return exec_err!("TestExtensionCodec only expects Rank UDWF");
};
@@ -630,7 +630,7 @@ pub(crate) mod tests {
let returned_udf = foreign_codec.try_decode_udaf(udf.name(), &bytes)?;
- assert!(returned_udf.inner().as_any().is::<Sum>());
+ assert!((returned_udf.inner().as_ref() as &dyn Any).is::<Sum>());
Ok(())
}
@@ -654,7 +654,7 @@ pub(crate) mod tests {
let returned_udf = foreign_codec.try_decode_udwf(udf.name(), &bytes)?;
- assert!(returned_udf.inner().as_any().is::<Rank>());
+ assert!((returned_udf.inner().as_ref() as &dyn Any).is::<Rank>());
Ok(())
}
diff --git a/datafusion/ffi/src/udaf/mod.rs b/datafusion/ffi/src/udaf/mod.rs
index 8e791b28b1..d3cb3ca7bb 100644
--- a/datafusion/ffi/src/udaf/mod.rs
+++ b/datafusion/ffi/src/udaf/mod.rs
@@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.
+use std::any::Any;
use std::ffi::c_void;
use std::hash::{Hash, Hasher};
use std::sync::Arc;
@@ -371,7 +372,9 @@ impl Clone for FFI_AggregateUDF {
impl From<Arc<AggregateUDF>> for FFI_AggregateUDF {
fn from(udaf: Arc<AggregateUDF>) -> Self {
- if let Some(udaf) =
udaf.inner().as_any().downcast_ref::<ForeignAggregateUDF>() {
+ if let Some(udaf) =
+ (udaf.inner().as_ref() as &dyn
Any).downcast_ref::<ForeignAggregateUDF>()
+ {
return udaf.udaf.clone();
}
@@ -457,10 +460,6 @@ impl From<&FFI_AggregateUDF> for Arc<dyn AggregateUDFImpl>
{
}
impl AggregateUDFImpl for ForeignAggregateUDF {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
self.udaf.name.as_str()
}
@@ -663,10 +662,6 @@ mod tests {
}
impl AggregateUDFImpl for SumWithCopiedMetadata {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
self.inner.name()
}
@@ -860,14 +855,17 @@ mod tests {
// Verify local libraries can be downcast to their original
let foreign_udaf: Arc<dyn AggregateUDFImpl> = (&ffi_udaf).into();
- assert!(foreign_udaf.as_any().downcast_ref::<Sum>().is_some());
+ assert!(
+ (foreign_udaf.as_ref() as &dyn Any)
+ .downcast_ref::<Sum>()
+ .is_some()
+ );
// Verify different library markers generate foreign providers
ffi_udaf.library_marker_id = crate::mock_foreign_marker_id;
let foreign_udaf: Arc<dyn AggregateUDFImpl> = (&ffi_udaf).into();
assert!(
- foreign_udaf
- .as_any()
+ (foreign_udaf.as_ref() as &dyn Any)
.downcast_ref::<ForeignAggregateUDF>()
.is_some()
);
diff --git a/datafusion/ffi/src/udwf/mod.rs b/datafusion/ffi/src/udwf/mod.rs
index 2e4bd0a294..7b5183f7f6 100644
--- a/datafusion/ffi/src/udwf/mod.rs
+++ b/datafusion/ffi/src/udwf/mod.rs
@@ -222,7 +222,9 @@ impl Clone for FFI_WindowUDF {
impl From<Arc<WindowUDF>> for FFI_WindowUDF {
fn from(udf: Arc<WindowUDF>) -> Self {
- if let Some(udwf) =
udf.inner().as_any().downcast_ref::<ForeignWindowUDF>() {
+ if let Some(udwf) = (udf.inner().as_ref() as &dyn std::any::Any)
+ .downcast_ref::<ForeignWindowUDF>()
+ {
return udwf.udf.clone();
}
@@ -306,10 +308,6 @@ impl From<&FFI_WindowUDF> for Arc<dyn WindowUDFImpl> {
}
impl WindowUDFImpl for ForeignWindowUDF {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
&self.name
}
@@ -477,8 +475,7 @@ mod tests {
// Verify local libraries can be downcast to their original
let foreign_udwf: Arc<dyn WindowUDFImpl> = (&ffi_udwf).into();
assert!(
- foreign_udwf
- .as_any()
+ (foreign_udwf.as_ref() as &dyn std::any::Any)
.downcast_ref::<WindowShift>()
.is_some()
);
@@ -487,8 +484,7 @@ mod tests {
ffi_udwf.library_marker_id = crate::mock_foreign_marker_id;
let foreign_udwf: Arc<dyn WindowUDFImpl> = (&ffi_udwf).into();
assert!(
- foreign_udwf
- .as_any()
+ (foreign_udwf.as_ref() as &dyn std::any::Any)
.downcast_ref::<ForeignWindowUDF>()
.is_some()
);
diff --git a/datafusion/functions-aggregate/src/approx_distinct.rs
b/datafusion/functions-aggregate/src/approx_distinct.rs
index 0a806b31cc..40da98c3eb 100644
--- a/datafusion/functions-aggregate/src/approx_distinct.rs
+++ b/datafusion/functions-aggregate/src/approx_distinct.rs
@@ -42,7 +42,6 @@ use datafusion_expr::{
};
use datafusion_functions_aggregate_common::noop_accumulator::NoopAccumulator;
use datafusion_macros::user_doc;
-use std::any::Any;
use std::fmt::{Debug, Formatter};
use std::hash::{BuildHasher, Hash};
use std::marker::PhantomData;
@@ -304,10 +303,6 @@ impl ApproxDistinct {
}
impl AggregateUDFImpl for ApproxDistinct {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"approx_distinct"
}
diff --git a/datafusion/functions-aggregate/src/approx_median.rs
b/datafusion/functions-aggregate/src/approx_median.rs
index 2205b009ec..c016ada695 100644
--- a/datafusion/functions-aggregate/src/approx_median.rs
+++ b/datafusion/functions-aggregate/src/approx_median.rs
@@ -21,7 +21,6 @@ use arrow::datatypes::DataType::{Float64, UInt64};
use arrow::datatypes::{DataType, Field, FieldRef};
use datafusion_common::types::NativeType;
use datafusion_functions_aggregate_common::noop_accumulator::NoopAccumulator;
-use std::any::Any;
use std::fmt::Debug;
use std::sync::Arc;
@@ -92,10 +91,6 @@ impl ApproxMedian {
}
impl AggregateUDFImpl for ApproxMedian {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
if args.input_fields[0].data_type().is_null() {
Ok(vec![
diff --git a/datafusion/functions-aggregate/src/approx_percentile_cont.rs
b/datafusion/functions-aggregate/src/approx_percentile_cont.rs
index 392a044d01..5e9e5beb0c 100644
--- a/datafusion/functions-aggregate/src/approx_percentile_cont.rs
+++ b/datafusion/functions-aggregate/src/approx_percentile_cont.rs
@@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.
-use std::any::Any;
use std::fmt::Debug;
use std::mem::size_of_val;
use std::sync::Arc;
@@ -239,10 +238,6 @@ fn validate_input_max_size_expr(expr: &Arc<dyn
PhysicalExpr>) -> Result<usize> {
}
impl AggregateUDFImpl for ApproxPercentileCont {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
/// See [`TDigest::to_scalar_state()`] for a description of the serialized
/// state.
fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
diff --git
a/datafusion/functions-aggregate/src/approx_percentile_cont_with_weight.rs
b/datafusion/functions-aggregate/src/approx_percentile_cont_with_weight.rs
index 6fd90130e6..81a4787dd5 100644
--- a/datafusion/functions-aggregate/src/approx_percentile_cont_with_weight.rs
+++ b/datafusion/functions-aggregate/src/approx_percentile_cont_with_weight.rs
@@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.
-use std::any::Any;
use std::fmt::Debug;
use std::hash::Hash;
use std::mem::size_of_val;
@@ -152,10 +151,6 @@ impl ApproxPercentileContWithWeight {
}
impl AggregateUDFImpl for ApproxPercentileContWithWeight {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"approx_percentile_cont_with_weight"
}
diff --git a/datafusion/functions-aggregate/src/array_agg.rs
b/datafusion/functions-aggregate/src/array_agg.rs
index 9ea3a383a8..861d7712ba 100644
--- a/datafusion/functions-aggregate/src/array_agg.rs
+++ b/datafusion/functions-aggregate/src/array_agg.rs
@@ -96,10 +96,6 @@ impl Default for ArrayAgg {
}
impl AggregateUDFImpl for ArrayAgg {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"array_agg"
}
diff --git a/datafusion/functions-aggregate/src/average.rs
b/datafusion/functions-aggregate/src/average.rs
index 1ddb549ae8..bcccea3813 100644
--- a/datafusion/functions-aggregate/src/average.rs
+++ b/datafusion/functions-aggregate/src/average.rs
@@ -50,7 +50,6 @@ use
datafusion_functions_aggregate_common::aggregate::groups_accumulator::nulls:
use datafusion_functions_aggregate_common::utils::DecimalAverager;
use datafusion_macros::user_doc;
use log::debug;
-use std::any::Any;
use std::fmt::Debug;
use std::mem::{size_of, size_of_val};
use std::sync::Arc;
@@ -127,10 +126,6 @@ impl Default for Avg {
}
impl AggregateUDFImpl for Avg {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"avg"
}
diff --git a/datafusion/functions-aggregate/src/bit_and_or_xor.rs
b/datafusion/functions-aggregate/src/bit_and_or_xor.rs
index 48edbd5d4c..d730a6c1cb 100644
--- a/datafusion/functions-aggregate/src/bit_and_or_xor.rs
+++ b/datafusion/functions-aggregate/src/bit_and_or_xor.rs
@@ -17,7 +17,6 @@
//! Defines `BitAnd`, `BitOr`, `BitXor` and `BitXor DISTINCT` aggregate
accumulators
-use std::any::Any;
use std::collections::HashSet;
use std::fmt::{Display, Formatter};
use std::hash::Hash;
@@ -240,10 +239,6 @@ impl BitwiseOperation {
}
impl AggregateUDFImpl for BitwiseOperation {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
self.func_name
}
diff --git a/datafusion/functions-aggregate/src/bool_and_or.rs
b/datafusion/functions-aggregate/src/bool_and_or.rs
index 77b99cd1ae..3b900f1655 100644
--- a/datafusion/functions-aggregate/src/bool_and_or.rs
+++ b/datafusion/functions-aggregate/src/bool_and_or.rs
@@ -17,7 +17,6 @@
//! Defines physical expressions that can evaluated at runtime during query
execution
-use std::any::Any;
use std::mem::size_of_val;
use arrow::array::ArrayRef;
@@ -126,10 +125,6 @@ impl Default for BoolAnd {
}
impl AggregateUDFImpl for BoolAnd {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"bool_and"
}
@@ -259,10 +254,6 @@ impl Default for BoolOr {
}
impl AggregateUDFImpl for BoolOr {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"bool_or"
}
diff --git a/datafusion/functions-aggregate/src/correlation.rs
b/datafusion/functions-aggregate/src/correlation.rs
index ea0d711b3d..2621fcf0bf 100644
--- a/datafusion/functions-aggregate/src/correlation.rs
+++ b/datafusion/functions-aggregate/src/correlation.rs
@@ -17,7 +17,6 @@
//! [`Correlation`]: correlation sample aggregations.
-use std::any::Any;
use std::fmt::Debug;
use std::mem::size_of_val;
use std::sync::Arc;
@@ -96,11 +95,6 @@ impl Correlation {
}
impl AggregateUDFImpl for Correlation {
- /// Return a reference to Any that can be used for downcasting
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"corr"
}
diff --git a/datafusion/functions-aggregate/src/count.rs
b/datafusion/functions-aggregate/src/count.rs
index 67e799d489..81b6eda3f9 100644
--- a/datafusion/functions-aggregate/src/count.rs
+++ b/datafusion/functions-aggregate/src/count.rs
@@ -271,10 +271,6 @@ fn get_count_accumulator(data_type: &DataType) -> Box<dyn
Accumulator> {
}
impl AggregateUDFImpl for Count {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"count"
}
diff --git a/datafusion/functions-aggregate/src/covariance.rs
b/datafusion/functions-aggregate/src/covariance.rs
index 8252cf1b19..18d602ab33 100644
--- a/datafusion/functions-aggregate/src/covariance.rs
+++ b/datafusion/functions-aggregate/src/covariance.rs
@@ -88,10 +88,6 @@ impl CovarianceSample {
}
impl AggregateUDFImpl for CovarianceSample {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"covar_samp"
}
@@ -172,10 +168,6 @@ impl CovariancePopulation {
}
impl AggregateUDFImpl for CovariancePopulation {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"covar_pop"
}
diff --git a/datafusion/functions-aggregate/src/first_last.rs
b/datafusion/functions-aggregate/src/first_last.rs
index b339479b35..91964eba1a 100644
--- a/datafusion/functions-aggregate/src/first_last.rs
+++ b/datafusion/functions-aggregate/src/first_last.rs
@@ -17,7 +17,6 @@
//! Defines the FIRST_VALUE/LAST_VALUE aggregations.
-use std::any::Any;
use std::fmt::Debug;
use std::hash::Hash;
use std::mem::size_of_val;
@@ -112,10 +111,6 @@ impl FirstValue {
}
impl AggregateUDFImpl for FirstValue {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"first_value"
}
@@ -1052,10 +1047,6 @@ impl LastValue {
}
impl AggregateUDFImpl for LastValue {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"last_value"
}
diff --git a/datafusion/functions-aggregate/src/grouping.rs
b/datafusion/functions-aggregate/src/grouping.rs
index c7af2df4b1..a170a7e0c9 100644
--- a/datafusion/functions-aggregate/src/grouping.rs
+++ b/datafusion/functions-aggregate/src/grouping.rs
@@ -17,8 +17,6 @@
//! Defines physical expressions that can evaluated at runtime during query
execution
-use std::any::Any;
-
use arrow::datatypes::Field;
use arrow::datatypes::{DataType, FieldRef};
use datafusion_common::{Result, not_impl_err};
@@ -80,10 +78,6 @@ impl Grouping {
}
impl AggregateUDFImpl for Grouping {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"grouping"
}
diff --git a/datafusion/functions-aggregate/src/median.rs
b/datafusion/functions-aggregate/src/median.rs
index db769918d1..322932dcbf 100644
--- a/datafusion/functions-aggregate/src/median.rs
+++ b/datafusion/functions-aggregate/src/median.rs
@@ -105,10 +105,6 @@ impl Median {
}
impl AggregateUDFImpl for Median {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"median"
}
diff --git a/datafusion/functions-aggregate/src/min_max.rs
b/datafusion/functions-aggregate/src/min_max.rs
index ee8f7ac753..9d05c57b02 100644
--- a/datafusion/functions-aggregate/src/min_max.rs
+++ b/datafusion/functions-aggregate/src/min_max.rs
@@ -203,10 +203,6 @@ impl FromColumnStatistics for Max {
}
impl AggregateUDFImpl for Max {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"max"
}
@@ -490,10 +486,6 @@ impl FromColumnStatistics for Min {
}
impl AggregateUDFImpl for Min {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"min"
}
diff --git a/datafusion/functions-aggregate/src/nth_value.rs
b/datafusion/functions-aggregate/src/nth_value.rs
index bc343a1969..0d76451955 100644
--- a/datafusion/functions-aggregate/src/nth_value.rs
+++ b/datafusion/functions-aggregate/src/nth_value.rs
@@ -18,7 +18,6 @@
//! Defines NTH_VALUE aggregate expression which may specify ordering
requirement
//! that can evaluated at runtime during query execution
-use std::any::Any;
use std::collections::VecDeque;
use std::mem::{size_of, size_of_val};
use std::sync::Arc;
@@ -112,10 +111,6 @@ impl Default for NthValueAgg {
}
impl AggregateUDFImpl for NthValueAgg {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"nth_value"
}
diff --git a/datafusion/functions-aggregate/src/percentile_cont.rs
b/datafusion/functions-aggregate/src/percentile_cont.rs
index 1aa150b563..8a37ceef51 100644
--- a/datafusion/functions-aggregate/src/percentile_cont.rs
+++ b/datafusion/functions-aggregate/src/percentile_cont.rs
@@ -163,10 +163,6 @@ impl PercentileCont {
}
impl AggregateUDFImpl for PercentileCont {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"percentile_cont"
}
diff --git a/datafusion/functions-aggregate/src/regr.rs
b/datafusion/functions-aggregate/src/regr.rs
index 7fef8ac981..3a68672abb 100644
--- a/datafusion/functions-aggregate/src/regr.rs
+++ b/datafusion/functions-aggregate/src/regr.rs
@@ -27,7 +27,6 @@ use datafusion_expr::utils::format_state_name;
use datafusion_expr::{
Accumulator, AggregateUDFImpl, Documentation, Signature, Volatility,
};
-use std::any::Any;
use std::fmt::Debug;
use std::hash::Hash;
use std::mem::size_of_val;
@@ -442,10 +441,6 @@ fn get_regr_docs() -> &'static HashMap<RegrType,
Documentation> {
}
impl AggregateUDFImpl for Regr {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
self.func_name
}
diff --git a/datafusion/functions-aggregate/src/stddev.rs
b/datafusion/functions-aggregate/src/stddev.rs
index f4d4a79705..68e38a3b8d 100644
--- a/datafusion/functions-aggregate/src/stddev.rs
+++ b/datafusion/functions-aggregate/src/stddev.rs
@@ -17,7 +17,6 @@
//! Defines physical expressions that can evaluated at runtime during query
execution
-use std::any::Any;
use std::fmt::Debug;
use std::hash::Hash;
use std::mem::align_of_val;
@@ -85,11 +84,6 @@ impl Stddev {
}
impl AggregateUDFImpl for Stddev {
- /// Return a reference to Any that can be used for downcasting
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"stddev"
}
@@ -192,11 +186,6 @@ impl StddevPop {
}
impl AggregateUDFImpl for StddevPop {
- /// Return a reference to Any that can be used for downcasting
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"stddev_pop"
}
diff --git a/datafusion/functions-aggregate/src/string_agg.rs
b/datafusion/functions-aggregate/src/string_agg.rs
index ea3914b1e3..e62b26da99 100644
--- a/datafusion/functions-aggregate/src/string_agg.rs
+++ b/datafusion/functions-aggregate/src/string_agg.rs
@@ -17,7 +17,6 @@
//! [`StringAgg`] accumulator for the `string_agg` function
-use std::any::Any;
use std::hash::Hash;
use std::mem::size_of_val;
use std::sync::Arc;
@@ -152,10 +151,6 @@ impl Default for StringAgg {
/// - No DISTINCT / ORDER BY without GROUP BY: `SimpleStringAggAccumulator`
/// - With DISTINCT or ORDER BY: `StringAggAccumulator` (delegates to
`ArrayAgg`)
impl AggregateUDFImpl for StringAgg {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"string_agg"
}
diff --git a/datafusion/functions-aggregate/src/sum.rs
b/datafusion/functions-aggregate/src/sum.rs
index 4f638f2cb0..81efea1df2 100644
--- a/datafusion/functions-aggregate/src/sum.rs
+++ b/datafusion/functions-aggregate/src/sum.rs
@@ -45,7 +45,6 @@ use datafusion_expr::{
use
datafusion_functions_aggregate_common::aggregate::groups_accumulator::prim_op::PrimitiveGroupsAccumulator;
use
datafusion_functions_aggregate_common::aggregate::sum_distinct::DistinctSumAccumulator;
use datafusion_macros::user_doc;
-use std::any::Any;
use std::mem::size_of_val;
make_udaf_expr_and_func!(
@@ -201,10 +200,6 @@ impl Default for Sum {
}
impl AggregateUDFImpl for Sum {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"sum"
}
diff --git a/datafusion/functions-aggregate/src/variance.rs
b/datafusion/functions-aggregate/src/variance.rs
index fb089ba4f9..ce3e00b9ff 100644
--- a/datafusion/functions-aggregate/src/variance.rs
+++ b/datafusion/functions-aggregate/src/variance.rs
@@ -84,10 +84,6 @@ impl VarianceSample {
}
impl AggregateUDFImpl for VarianceSample {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"var"
}
@@ -184,10 +180,6 @@ impl VariancePopulation {
}
impl AggregateUDFImpl for VariancePopulation {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"var_pop"
}
diff --git a/datafusion/functions-window/src/cume_dist.rs
b/datafusion/functions-window/src/cume_dist.rs
index 8e1cb1b1e6..9d0f082dae 100644
--- a/datafusion/functions-window/src/cume_dist.rs
+++ b/datafusion/functions-window/src/cume_dist.rs
@@ -30,7 +30,6 @@ use
datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
use datafusion_macros::user_doc;
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
use field::WindowUDFFieldArgs;
-use std::any::Any;
use std::fmt::Debug;
use std::iter;
use std::ops::Range;
@@ -85,11 +84,6 @@ impl Default for CumeDist {
}
impl WindowUDFImpl for CumeDist {
- /// Return a reference to Any that can be used for downcasting
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"cume_dist"
}
diff --git a/datafusion/functions-window/src/lead_lag.rs
b/datafusion/functions-window/src/lead_lag.rs
index 0acd206d29..604f1d4a0e 100644
--- a/datafusion/functions-window/src/lead_lag.rs
+++ b/datafusion/functions-window/src/lead_lag.rs
@@ -33,7 +33,6 @@ use
datafusion_functions_window_common::field::WindowUDFFieldArgs;
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
use datafusion_physical_expr::expressions;
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
-use std::any::Any;
use std::cmp::min;
use std::collections::VecDeque;
use std::hash::Hash;
@@ -237,10 +236,6 @@ fn get_lead_doc() -> &'static Documentation {
}
impl WindowUDFImpl for WindowShift {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
self.kind.name()
}
diff --git a/datafusion/functions-window/src/macros.rs
b/datafusion/functions-window/src/macros.rs
index aeb54356f8..066dd43c17 100644
--- a/datafusion/functions-window/src/macros.rs
+++ b/datafusion/functions-window/src/macros.rs
@@ -39,7 +39,6 @@
/// # Example
///
/// ```
-/// # use std::any::Any;
/// use arrow::datatypes::FieldRef;
/// # use datafusion_common::arrow::datatypes::{DataType, Field};
/// # use datafusion_expr::{PartitionEvaluator, Signature, Volatility,
WindowUDFImpl};
@@ -72,9 +71,6 @@
/// # }
/// #
/// # impl WindowUDFImpl for SimpleUDWF {
-/// # fn as_any(&self) -> &dyn Any {
-/// # self
-/// # }
/// # fn name(&self) -> &str {
/// # "simple_user_defined_window_function"
/// # }
@@ -137,7 +133,6 @@ macro_rules! get_or_init_udwf {
///
/// 1. With Zero Parameters
/// ```
-/// # use std::any::Any;
/// use arrow::datatypes::FieldRef;
/// # use datafusion_common::arrow::datatypes::{DataType, Field};
/// # use datafusion_expr::{PartitionEvaluator, Signature, Volatility,
WindowUDFImpl};
@@ -184,9 +179,6 @@ macro_rules! get_or_init_udwf {
/// # }
/// # }
/// # impl WindowUDFImpl for RowNumber {
-/// # fn as_any(&self) -> &dyn Any {
-/// # self
-/// # }
/// # fn name(&self) -> &str {
/// # "row_number"
/// # }
@@ -207,7 +199,6 @@ macro_rules! get_or_init_udwf {
///
/// 2. With Multiple Parameters
/// ```
-/// # use std::any::Any;
/// use arrow::datatypes::FieldRef;
/// #
/// # use datafusion_expr::{
@@ -273,9 +264,6 @@ macro_rules! get_or_init_udwf {
/// # }
/// #
/// # impl WindowUDFImpl for Lead {
-/// # fn as_any(&self) -> &dyn Any {
-/// # self
-/// # }
/// # fn name(&self) -> &str {
/// # "lead"
/// # }
@@ -352,7 +340,6 @@ macro_rules! create_udwf_expr {
/// 1. Uses default constructor for UDWF.
///
/// ```
-/// # use std::any::Any;
/// use arrow::datatypes::FieldRef;
/// # use datafusion_common::arrow::datatypes::{DataType, Field};
/// # use datafusion_expr::{PartitionEvaluator, Signature, Volatility,
WindowUDFImpl};
@@ -392,9 +379,6 @@ macro_rules! create_udwf_expr {
/// # }
/// #
/// # impl WindowUDFImpl for SimpleUDWF {
-/// # fn as_any(&self) -> &dyn Any {
-/// # self
-/// # }
/// # fn name(&self) -> &str {
/// # "simple_user_defined_window_function"
/// # }
@@ -417,7 +401,6 @@ macro_rules! create_udwf_expr {
/// 2. Uses a custom constructor for UDWF.
///
/// ```
-/// # use std::any::Any;
/// use arrow::datatypes::FieldRef;
/// # use datafusion_common::arrow::datatypes::{DataType, Field};
/// # use datafusion_expr::{PartitionEvaluator, Signature, Volatility,
WindowUDFImpl};
@@ -458,9 +441,6 @@ macro_rules! create_udwf_expr {
/// # }
/// # }
/// # impl WindowUDFImpl for RowNumber {
-/// # fn as_any(&self) -> &dyn Any {
-/// # self
-/// # }
/// # fn name(&self) -> &str {
/// # "row_number"
/// # }
@@ -483,7 +463,6 @@ macro_rules! create_udwf_expr {
/// 3. Uses default constructor for UDWF
///
/// ```
-/// # use std::any::Any;
/// use arrow::datatypes::FieldRef;
/// #
/// # use datafusion_expr::{
@@ -546,9 +525,6 @@ macro_rules! create_udwf_expr {
/// # }
/// #
/// # impl WindowUDFImpl for Lead {
-/// # fn as_any(&self) -> &dyn Any {
-/// # self
-/// # }
/// # fn name(&self) -> &str {
/// # "lead"
/// # }
@@ -573,7 +549,6 @@ macro_rules! create_udwf_expr {
/// 4. Uses custom constructor for UDWF
///
/// ```
-/// # use std::any::Any;
/// use arrow::datatypes::FieldRef;
/// #
/// # use datafusion_expr::{
@@ -637,9 +612,6 @@ macro_rules! create_udwf_expr {
/// # }
/// #
/// # impl WindowUDFImpl for Lead {
-/// # fn as_any(&self) -> &dyn Any {
-/// # self
-/// # }
/// # fn name(&self) -> &str {
/// # "lead"
/// # }
diff --git a/datafusion/functions-window/src/nth_value.rs
b/datafusion/functions-window/src/nth_value.rs
index f8761e7593..6c6139405c 100644
--- a/datafusion/functions-window/src/nth_value.rs
+++ b/datafusion/functions-window/src/nth_value.rs
@@ -34,7 +34,6 @@ use datafusion_functions_window_common::field;
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
use field::WindowUDFFieldArgs;
-use std::any::Any;
use std::cmp::Ordering;
use std::fmt::Debug;
use std::hash::Hash;
@@ -251,10 +250,6 @@ fn get_nth_value_doc() -> &'static Documentation {
}
impl WindowUDFImpl for NthValue {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
self.kind.name()
}
diff --git a/datafusion/functions-window/src/ntile.rs
b/datafusion/functions-window/src/ntile.rs
index 1f9b2344e5..6d9215f78e 100644
--- a/datafusion/functions-window/src/ntile.rs
+++ b/datafusion/functions-window/src/ntile.rs
@@ -32,7 +32,6 @@ use
datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
use datafusion_macros::user_doc;
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
use field::WindowUDFFieldArgs;
-use std::any::Any;
use std::fmt::Debug;
use std::sync::Arc;
@@ -109,10 +108,6 @@ impl Default for Ntile {
}
impl WindowUDFImpl for Ntile {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"ntile"
}
diff --git a/datafusion/functions-window/src/rank.rs
b/datafusion/functions-window/src/rank.rs
index ee8546703b..d18bd07489 100644
--- a/datafusion/functions-window/src/rank.rs
+++ b/datafusion/functions-window/src/rank.rs
@@ -34,7 +34,6 @@ use datafusion_functions_window_common::field;
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
use field::WindowUDFFieldArgs;
-use std::any::Any;
use std::fmt::Debug;
use std::hash::Hash;
use std::iter;
@@ -197,10 +196,6 @@ fn get_percent_rank_doc() -> &'static Documentation {
}
impl WindowUDFImpl for Rank {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
&self.name
}
diff --git a/datafusion/functions-window/src/row_number.rs
b/datafusion/functions-window/src/row_number.rs
index 7dc992872b..eb48a31753 100644
--- a/datafusion/functions-window/src/row_number.rs
+++ b/datafusion/functions-window/src/row_number.rs
@@ -32,7 +32,6 @@ use
datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
use datafusion_macros::user_doc;
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
use field::WindowUDFFieldArgs;
-use std::any::Any;
use std::fmt::Debug;
use std::ops::Range;
use std::sync::Arc;
@@ -91,10 +90,6 @@ impl Default for RowNumber {
}
impl WindowUDFImpl for RowNumber {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"row_number"
}
diff --git a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
index 855e41ddf2..4778f75e3a 100644
--- a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
+++ b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
@@ -4961,10 +4961,6 @@ mod tests {
}
impl AggregateUDFImpl for SimplifyMockUdaf {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"mock_simplify"
}
@@ -5042,10 +5038,6 @@ mod tests {
}
impl WindowUDFImpl for SimplifyMockUdwf {
- fn as_any(&self) -> &dyn std::any::Any {
- self
- }
-
fn name(&self) -> &str {
"mock_simplify"
}
diff --git a/datafusion/physical-expr/src/aggregate.rs
b/datafusion/physical-expr/src/aggregate.rs
index d031ad7d85..3fd2b42b2e 100644
--- a/datafusion/physical-expr/src/aggregate.rs
+++ b/datafusion/physical-expr/src/aggregate.rs
@@ -126,10 +126,6 @@ impl AggregateExprBuilder {
/// # }
/// #
/// # impl AggregateUDFImpl for FirstValueUdf {
- /// # fn as_any(&self) -> &dyn Any {
- /// # unimplemented!()
- /// # }
- /// #
/// # fn name(&self) -> &str {
/// # unimplemented!()
/// # }
diff --git a/datafusion/proto/tests/cases/mod.rs
b/datafusion/proto/tests/cases/mod.rs
index 4584991cfd..3abbaccf79 100644
--- a/datafusion/proto/tests/cases/mod.rs
+++ b/datafusion/proto/tests/cases/mod.rs
@@ -26,7 +26,6 @@ use datafusion_expr::{
};
use datafusion_functions_window_common::field::WindowUDFFieldArgs;
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
-use std::any::Any;
use std::fmt::Debug;
use std::hash::Hash;
use std::sync::Arc;
@@ -102,10 +101,6 @@ impl MyAggregateUDF {
}
impl AggregateUDFImpl for MyAggregateUDF {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"aggregate_udf"
}
@@ -148,10 +143,6 @@ impl CustomUDWF {
}
impl WindowUDFImpl for CustomUDWF {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"custom_udwf"
}
diff --git a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs
b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs
index 0498419805..d29d6fc7cd 100644
--- a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs
+++ b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs
@@ -1527,7 +1527,9 @@ impl LogicalExtensionCodec for UDFExtensionCodec {
fn try_encode_udaf(&self, node: &AggregateUDF, buf: &mut Vec<u8>) ->
Result<()> {
let binding = node.inner();
- let udf = binding.as_any().downcast_ref::<MyAggregateUDF>().unwrap();
+ let udf = (binding.as_ref() as &dyn Any)
+ .downcast_ref::<MyAggregateUDF>()
+ .unwrap();
let proto = MyAggregateUdfNode {
result: udf.result.clone(),
};
@@ -2779,10 +2781,6 @@ fn roundtrip_window() {
}
impl WindowUDFImpl for SimpleWindowUDF {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"dummy_udwf"
}
diff --git a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs
b/datafusion/proto/tests/cases/roundtrip_physical_plan.rs
index 2b744a8fbd..10b50930b4 100644
--- a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs
+++ b/datafusion/proto/tests/cases/roundtrip_physical_plan.rs
@@ -1307,7 +1307,8 @@ impl PhysicalExtensionCodec for UDFExtensionCodec {
fn try_encode_udaf(&self, node: &AggregateUDF, buf: &mut Vec<u8>) ->
Result<()> {
let binding = node.inner();
- if let Some(udf) = binding.as_any().downcast_ref::<MyAggregateUDF>() {
+ if let Some(udf) = (binding.as_ref() as &dyn
Any).downcast_ref::<MyAggregateUDF>()
+ {
let proto = MyAggregateUdfNode {
result: udf.result.clone(),
};
@@ -1334,7 +1335,7 @@ impl PhysicalExtensionCodec for UDFExtensionCodec {
fn try_encode_udwf(&self, node: &WindowUDF, buf: &mut Vec<u8>) ->
Result<()> {
let binding = node.inner();
- if let Some(udwf) = binding.as_any().downcast_ref::<CustomUDWF>() {
+ if let Some(udwf) = (binding.as_ref() as &dyn
Any).downcast_ref::<CustomUDWF>() {
let proto = CustomUDWFNode {
payload: udwf.payload.clone(),
};
diff --git a/datafusion/spark/src/function/aggregate/avg.rs
b/datafusion/spark/src/function/aggregate/avg.rs
index 9ad712713d..c504f5387f 100644
--- a/datafusion/spark/src/function/aggregate/avg.rs
+++ b/datafusion/spark/src/function/aggregate/avg.rs
@@ -31,7 +31,7 @@ use datafusion_expr::{
Accumulator, AggregateUDFImpl, Coercion, EmitTo, GroupsAccumulator,
ReversedUDAF,
Signature, TypeSignatureClass, Volatility,
};
-use std::{any::Any, sync::Arc};
+use std::sync::Arc;
/// AVG aggregate expression
/// Spark average aggregate expression. Differs from standard DataFusion
average aggregate
@@ -68,10 +68,6 @@ impl SparkAvg {
}
impl AggregateUDFImpl for SparkAvg {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
Ok(DataType::Float64)
}
diff --git a/datafusion/spark/src/function/aggregate/collect.rs
b/datafusion/spark/src/function/aggregate/collect.rs
index 50497e2826..5af0fd39cc 100644
--- a/datafusion/spark/src/function/aggregate/collect.rs
+++ b/datafusion/spark/src/function/aggregate/collect.rs
@@ -25,7 +25,7 @@ use datafusion_expr::{Accumulator, AggregateUDFImpl,
Signature, Volatility};
use datafusion_functions_aggregate::array_agg::{
ArrayAggAccumulator, DistinctArrayAggAccumulator,
};
-use std::{any::Any, sync::Arc};
+use std::sync::Arc;
// Spark implementation of collect_list/collect_set aggregate function.
// Differs from DataFusion ArrayAgg in the following ways:
@@ -54,10 +54,6 @@ impl SparkCollectList {
}
impl AggregateUDFImpl for SparkCollectList {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"collect_list"
}
@@ -116,10 +112,6 @@ impl SparkCollectSet {
}
impl AggregateUDFImpl for SparkCollectSet {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"collect_set"
}
diff --git a/datafusion/spark/src/function/aggregate/try_sum.rs
b/datafusion/spark/src/function/aggregate/try_sum.rs
index 0197747ca9..3918dea0f5 100644
--- a/datafusion/spark/src/function/aggregate/try_sum.rs
+++ b/datafusion/spark/src/function/aggregate/try_sum.rs
@@ -24,7 +24,6 @@ use datafusion_common::{Result, ScalarValue, downcast_value,
exec_err, not_impl_
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
use datafusion_expr::utils::format_state_name;
use datafusion_expr::{Accumulator, AggregateUDFImpl, Signature, Volatility};
-use std::any::Any;
use std::fmt::{Debug, Formatter};
use std::mem::size_of_val;
@@ -248,10 +247,6 @@ fn exceeds_decimal128_precision(sum: i128, p: u8) -> bool {
}
impl AggregateUDFImpl for SparkTrySum {
- fn as_any(&self) -> &dyn Any {
- self
- }
-
fn name(&self) -> &str {
"try_sum"
}
diff --git a/docs/source/library-user-guide/upgrading/54.0.0.md
b/docs/source/library-user-guide/upgrading/54.0.0.md
index 454a8de3d1..d8758e1342 100644
--- a/docs/source/library-user-guide/upgrading/54.0.0.md
+++ b/docs/source/library-user-guide/upgrading/54.0.0.md
@@ -124,12 +124,15 @@ let mut stats =
Arc::unwrap_or_clone(plan.partition_statistics(None)?);
stats.column_statistics[0].min_value = ...;
```
-### Remove `as_any` from `ScalarUDFImpl`
+### Remove `as_any` from `ScalarUDFImpl`, `AggregateUDFImpl`, and
`WindowUDFImpl`
Now that we have a more recent minimum version of Rust, we can take advantage
of
-trait upcasting for Scalar UDFs. This reduces the amount of boilerplate code
that
-users need to do to create a UDF. In your implementations, you can simply
remove
-this function. The below diff is an example from the associated PR
+trait upcasting for UDFs. This reduces the amount of boilerplate code that
+users need to do to create a UDF. In your implementations of `ScalarUDFImpl`,
+`AggregateUDFImpl`, and `WindowUDFImpl`, you can simply remove the `as_any`
+function. The below diffs are examples from the associated PRs.
+
+**Scalar UDFs:**
```diff
impl ScalarUDFImpl for MyEq {
@@ -145,7 +148,39 @@ this function. The below diff is an example from the
associated PR
}
```
-If you have a function that is downcasting a scalar function, you can replace
+**Aggregate UDFs:**
+
+```diff
+ impl AggregateUDFImpl for GeoMeanUdf {
+- fn as_any(&self) -> &dyn Any {
+- self
+- }
+-
+ fn name(&self) -> &str {
+ "geo_mean"
+ }
+
+ ...
+ }
+```
+
+**Window UDFs:**
+
+```diff
+ impl WindowUDFImpl for SmoothIt {
+- fn as_any(&self) -> &dyn Any {
+- self
+- }
+-
+ fn name(&self) -> &str {
+ "smooth_it"
+ }
+
+ ...
+ }
+```
+
+If you have a function that is downcasting a UDF, you can replace
the call to `.as_any()` with `.as_ref() as &dyn Any`. For example
**Before:**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]