renato2099 commented on code in PR #18916:
URL: https://github.com/apache/datafusion/pull/18916#discussion_r2573154712


##########
datafusion/ffi/src/expr/columnar_value.rs:
##########
@@ -0,0 +1,86 @@
+// 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 abi_stable::{std_types::RVec, StableAbi};
+use datafusion_common::DataFusionError;
+use datafusion_expr::ColumnarValue;
+
+use crate::{
+    arrow_wrappers::WrappedArray,
+    expr::util::{rvec_u8_to_scalar_value, scalar_value_to_rvec_u8},
+};
+
+#[repr(C)]
+#[derive(Debug, StableAbi)]
+#[allow(non_camel_case_types)]
+pub enum FFI_ColumnarValue {
+    Array(WrappedArray),
+    Scalar(RVec<u8>),
+}
+
+impl TryFrom<ColumnarValue> for FFI_ColumnarValue {
+    type Error = DataFusionError;
+    fn try_from(value: ColumnarValue) -> Result<Self, Self::Error> {
+        Ok(match value {
+            ColumnarValue::Array(v) => {
+                FFI_ColumnarValue::Array(WrappedArray::try_from(&v)?)
+            }
+            ColumnarValue::Scalar(v) => {
+                FFI_ColumnarValue::Scalar(scalar_value_to_rvec_u8(&v)?)
+            }
+        })
+    }
+}
+
+impl TryFrom<FFI_ColumnarValue> for ColumnarValue {
+    type Error = DataFusionError;
+    fn try_from(value: FFI_ColumnarValue) -> Result<Self, Self::Error> {
+        Ok(match value {
+            FFI_ColumnarValue::Array(v) => ColumnarValue::Array(v.try_into()?),
+            FFI_ColumnarValue::Scalar(v) => {
+                ColumnarValue::Scalar(rvec_u8_to_scalar_value(&v)?)
+            }
+        })
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use arrow::array::create_array;
+    use datafusion_common::{DataFusionError, ScalarValue};
+    use datafusion_expr::ColumnarValue;
+
+    use crate::expr::columnar_value::FFI_ColumnarValue;
+
+    #[test]
+    fn ffi_columnar_value_round_trip() -> Result<(), DataFusionError> {
+        let array = create_array!(Int32, [1, 2, 3, 4, 5]);
+
+        for original in [
+            ColumnarValue::Array(array),
+            ColumnarValue::Scalar(ScalarValue::Int32(Some(1))),

Review Comment:
   maybe we could also consider a `null` scalar since that is a bit of an edge 
case 
   ```
   let original = ScalarValue::Int32(None);
   ```



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