Skip to content

Commit 02457bd

Browse files
timsaucerclaude
andcommitted
Use WindowUDFImpl::downcast_ref and is() instead of as &dyn Any patterns
Replaces `(udwf.inner().as_ref() as &dyn Any).downcast_ref::<T>()` and `.is::<T>()` call sites with the new inherent methods on `dyn WindowUDFImpl`. Removes now-unused `std::any::Any` imports. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fa7fa2d commit 02457bd

4 files changed

Lines changed: 7 additions & 19 deletions

File tree

datafusion/ffi/src/proto/logical_extension_codec.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ impl LogicalExtensionCodec for ForeignLogicalExtensionCodec {
489489

490490
#[cfg(test)]
491491
mod tests {
492-
use std::any::Any;
493492
use std::sync::Arc;
494493

495494
use arrow::array::record_batch;
@@ -704,7 +703,7 @@ mod tests {
704703

705704
let returned_udf = foreign_codec.try_decode_udwf(udf.name(), &bytes)?;
706705

707-
assert!((returned_udf.inner().as_ref() as &dyn Any).is::<Rank>());
706+
assert!(returned_udf.inner().is::<Rank>());
708707

709708
Ok(())
710709
}

datafusion/ffi/src/proto/physical_extension_codec.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ impl PhysicalExtensionCodec for ForeignPhysicalExtensionCodec {
410410

411411
#[cfg(test)]
412412
pub(crate) mod tests {
413-
use std::any::Any;
414413
use std::sync::Arc;
415414

416415
use arrow_schema::{DataType, Field, Schema};
@@ -550,7 +549,7 @@ pub(crate) mod tests {
550549
buf.push(Self::MAGIC_NUMBER);
551550

552551
let udf = node.inner();
553-
let Some(udf) = (udf.as_ref() as &dyn Any).downcast_ref::<Rank>() else {
552+
let Some(udf) = udf.downcast_ref::<Rank>() else {
554553
return exec_err!("TestExtensionCodec only expects Rank UDWF");
555554
};
556555

@@ -654,7 +653,7 @@ pub(crate) mod tests {
654653

655654
let returned_udf = foreign_codec.try_decode_udwf(udf.name(), &bytes)?;
656655

657-
assert!((returned_udf.inner().as_ref() as &dyn Any).is::<Rank>());
656+
assert!(returned_udf.inner().is::<Rank>());
658657

659658
Ok(())
660659
}

datafusion/ffi/src/udwf/mod.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ impl Clone for FFI_WindowUDF {
222222

223223
impl From<Arc<WindowUDF>> for FFI_WindowUDF {
224224
fn from(udf: Arc<WindowUDF>) -> Self {
225-
if let Some(udwf) = (udf.inner().as_ref() as &dyn std::any::Any)
226-
.downcast_ref::<ForeignWindowUDF>()
227-
{
225+
if let Some(udwf) = udf.inner().downcast_ref::<ForeignWindowUDF>() {
228226
return udwf.udf.clone();
229227
}
230228

@@ -474,20 +472,12 @@ mod tests {
474472

475473
// Verify local libraries can be downcast to their original
476474
let foreign_udwf: Arc<dyn WindowUDFImpl> = (&ffi_udwf).into();
477-
assert!(
478-
(foreign_udwf.as_ref() as &dyn std::any::Any)
479-
.downcast_ref::<WindowShift>()
480-
.is_some()
481-
);
475+
assert!(foreign_udwf.is::<WindowShift>());
482476

483477
// Verify different library markers generate foreign providers
484478
ffi_udwf.library_marker_id = crate::mock_foreign_marker_id;
485479
let foreign_udwf: Arc<dyn WindowUDFImpl> = (&ffi_udwf).into();
486-
assert!(
487-
(foreign_udwf.as_ref() as &dyn std::any::Any)
488-
.downcast_ref::<ForeignWindowUDF>()
489-
.is_some()
490-
);
480+
assert!(foreign_udwf.is::<ForeignWindowUDF>());
491481

492482
Ok(())
493483
}

datafusion/proto/tests/cases/roundtrip_physical_plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ impl PhysicalExtensionCodec for UDFExtensionCodec {
13331333

13341334
fn try_encode_udwf(&self, node: &WindowUDF, buf: &mut Vec<u8>) -> Result<()> {
13351335
let binding = node.inner();
1336-
if let Some(udwf) = (binding.as_ref() as &dyn Any).downcast_ref::<CustomUDWF>() {
1336+
if let Some(udwf) = binding.downcast_ref::<CustomUDWF>() {
13371337
let proto = CustomUDWFNode {
13381338
payload: udwf.payload.clone(),
13391339
};

0 commit comments

Comments
 (0)