Copilot commented on code in PR #22797:
URL: https://github.com/apache/datafusion/pull/22797#discussion_r3652711644


##########
datafusion/ffi/src/udf/mod.rs:
##########
@@ -460,6 +487,19 @@ impl ScalarUDFImpl for ForeignScalarUDF {
 
         result.into()
     }
+
+    fn with_updated_config(&self, config: &ConfigOptions) -> Option<ScalarUDF> 
{
+        let config: FFI_ConfigOptions = config.into();
+
+        let result = unsafe { (self.udf.with_updated_config)(&self.udf, 
config) };
+
+        // The trait method is infallible, so a transport-level error (the 
config
+        // failing to round-trip on the provider side) degrades to `None`; the
+        // same outcome as a provider that does not specialize on config.
+        let updated = df_result!(result).ok()?.into_option()?;
+
+        Some(ScalarUDF::new_from_shared_impl((&updated).into()))
+    }
 }

Review Comment:
   `with_updated_config` receives an owned `FFI_ScalarUDF` from the provider, 
but then converts it via `(&updated).into()`. For the foreign path this 
triggers an extra `FFI_ScalarUDF::clone()` (and thus an extra cross-FFI 
clone/release cycle) because `From<&FFI_ScalarUDF> for Arc<dyn ScalarUDFImpl>` 
always clones the input when `library_marker_id` differs. You can avoid the 
redundant clone by building the `Arc<dyn ScalarUDFImpl>` from the owned 
`updated` value directly.



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

Reply via email to