paleolimbot commented on code in PR #4283:
URL: https://github.com/apache/datafusion-comet/pull/4283#discussion_r3311988049


##########
native/core/src/execution/rust_udf/adapter.rs:
##########
@@ -0,0 +1,322 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! `RustUdfAdapter`: wraps a UDF loaded from a cdylib as a DataFusion
+//! `ScalarUDFImpl` so it can plug into DataFusion's expression
+//! evaluation pipeline.
+
+use std::any::Any;
+use std::sync::Arc;
+
+use arrow::array::ArrayRef;
+use arrow::datatypes::DataType;
+use arrow::ffi::{from_ffi, to_ffi, FFI_ArrowArray, FFI_ArrowSchema};
+use datafusion::common::DataFusionError;
+use datafusion::logical_expr::{
+    ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, 
TypeSignature, Volatility,
+};
+use crate::execution::rust_udf::loader::{LoadedLibrary, LoadedUdf};
+use crate::execution::rust_udf::symbols;
+use crate::execution::rust_udf::{FreeErrFn, InvokeFn};
+
+/// DataFusion adapter for a Rust UDF loaded from a cdylib.
+///
+/// Holds:
+/// - an `Arc<LoadedLibrary>` so the cdylib outlives the adapter,
+/// - a clone of the per-UDF descriptor (`LoadedUdf`),
+/// - a precomputed DataFusion `Signature`,
+/// - cached raw function pointers to avoid per-call `dlsym` lookups.
+///
+/// On every batch, `invoke_with_args` exports each input via the Arrow
+/// C Data Interface, calls the cdylib's `comet_udf_invoke`, and imports
+/// the result.
+pub struct RustUdfHandle {

Review Comment:
   It's probably worth separating the dynamic library from the C Udf 
implementation (this seems like it couples them closely). Dynamic libraries are 
one way to manage these but passing the pointer address through Java (like the 
C Data interface) might be more flexible.



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