zhangfengcdt commented on code in PR #1094:
URL: https://github.com/apache/sedona-db/pull/1094#discussion_r3721345806


##########
c/sedona-extension/src/expr.rs:
##########
@@ -0,0 +1,451 @@
+// 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.
+
+use std::{
+    ffi::{c_int, CString},
+    fmt::{Debug, Display},
+    os::raw::{c_char, c_void},
+    ptr::null_mut,
+};
+
+use arrow_array::ffi::{FFI_ArrowArray, FFI_ArrowSchema};
+use arrow_schema::{DataType, Field};
+use datafusion_common::Result;
+use datafusion_execution::FunctionRegistry;
+use datafusion_expr::Expr;
+use sedona_common::{sedona_internal_datafusion_err, sedona_internal_err};
+
+pub use sedona_expr::placeholder_udf::{
+    PlaceholderRegistry, PlaceholderUDAF, PlaceholderUDF, PlaceholderUDWF,
+};
+
+use crate::{
+    extension::{SedonaCError, SedonaCExprView},
+    set_ffi_error,
+    utils::{
+        call_get_property_schema_impl, cstr_from_ptr_or_empty, 
parse_ffi_array_to_bytes,
+        PropertyValue, ERRNO_OK,
+    },
+};
+
+/// Wrapper around a [datafusion_expr::Expr] that can be exported across FFI.
+pub struct ExportedExprView<'a> {
+    expr: &'a Expr,
+}
+
+impl<'a> Debug for ExportedExprView<'a> {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("ExportedExprView")
+            .field("expr", &self.expr)
+            .finish()
+    }
+}
+
+impl<'a> ExportedExprView<'a> {
+    /// Create a new ExportedExprView from a reference to a datafusion Expr.
+    ///
+    /// The returned view is valid only as long as the referenced Expr remains 
alive.
+    pub fn new(expr: &'a Expr) -> Self {
+        Self { expr }
+    }
+
+    /// Get the inner expression reference.
+    pub fn expr(&self) -> &Expr {
+        self.expr
+    }
+
+    /// Get a FFI-compatible view of this expression.
+    ///
+    /// The returned [SedonaCExprView] is valid only as long as this 
ExportedExprView
+    /// remains alive. The caller must ensure they do not use the FFI view 
after
+    /// this object is dropped.
+    pub fn as_ffi_view(&self) -> SedonaCExprView {
+        SedonaCExprView {
+            get_property_schema: Some(c_expr_get_property_schema),
+            get_property: Some(c_expr_get_property),
+            reserved: null_mut(),
+            private_data: self as *const ExportedExprView as *const c_void,

Review Comment:
   Maybe point to Expr itself (self.expr) instead the wrapper object?



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

Reply via email to