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


##########
datafusion/ffi/src/expr/distribution.rs:
##########
@@ -0,0 +1,214 @@
+// 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;
+use abi_stable::StableAbi;
+use datafusion_common::DataFusionError;
+use datafusion_expr::statistics::{
+    BernoulliDistribution, Distribution, ExponentialDistribution, 
GaussianDistribution,
+    GenericDistribution, UniformDistribution,
+};
+
+use crate::expr::interval::FFI_Interval;
+use crate::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_Distribution {
+    Uniform(FFI_UniformDistribution),
+    Exponential(FFI_ExponentialDistribution),
+    Gaussian(FFI_GaussianDistribution),
+    Bernoulli(FFI_BernoulliDistribution),
+    Generic(FFI_GenericDistribution),
+}
+
+impl TryFrom<&Distribution> for FFI_Distribution {
+    type Error = DataFusionError;
+    fn try_from(value: &Distribution) -> Result<Self, Self::Error> {
+        match value {
+            Distribution::Uniform(d) => 
Ok(FFI_Distribution::Uniform(d.try_into()?)),
+            Distribution::Exponential(d) => {
+                Ok(FFI_Distribution::Exponential(d.try_into()?))
+            }
+            Distribution::Gaussian(d) => 
Ok(FFI_Distribution::Gaussian(d.try_into()?)),
+            Distribution::Bernoulli(d) => 
Ok(FFI_Distribution::Bernoulli(d.try_into()?)),
+            Distribution::Generic(d) => 
Ok(FFI_Distribution::Generic(d.try_into()?)),
+        }
+    }
+}
+
+impl TryFrom<&FFI_Distribution> for Distribution {
+    type Error = DataFusionError;
+    fn try_from(value: &FFI_Distribution) -> Result<Self, Self::Error> {
+        match value {
+            FFI_Distribution::Uniform(d) => d.try_into(),

Review Comment:
   I'm not sure what would happen on version mismatch here, but more generally 
version mismatch between stable definitions is very likely going to fail in 
other places as well. I've been trying to think of the best way to do checks 
for compatible versions and that's the reason we have `crate::version()` but I 
don't have a great way to use it at this point. At rerun we have some code that 
looks for known compatible versions, but it's not great: 
https://github.com/rerun-io/rerun/blob/main/rerun_py/rerun_sdk/rerun/catalog/_catalog_client.py#L28
 



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