Skip to main content

datafusion_ffi/
placement.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use datafusion_expr::ExpressionPlacement;
19
20#[expect(non_camel_case_types)]
21#[repr(u8)]
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum FFI_ExpressionPlacement {
24    Literal,
25    Column,
26    MoveTowardsLeafNodes,
27    KeepInPlace,
28}
29
30impl From<ExpressionPlacement> for FFI_ExpressionPlacement {
31    fn from(value: ExpressionPlacement) -> Self {
32        match value {
33            ExpressionPlacement::Literal => Self::Literal,
34            ExpressionPlacement::Column => Self::Column,
35            ExpressionPlacement::MoveTowardsLeafNodes => Self::MoveTowardsLeafNodes,
36            ExpressionPlacement::KeepInPlace => Self::KeepInPlace,
37        }
38    }
39}
40
41impl From<FFI_ExpressionPlacement> for ExpressionPlacement {
42    fn from(value: FFI_ExpressionPlacement) -> Self {
43        match value {
44            FFI_ExpressionPlacement::Literal => Self::Literal,
45            FFI_ExpressionPlacement::Column => Self::Column,
46            FFI_ExpressionPlacement::MoveTowardsLeafNodes => Self::MoveTowardsLeafNodes,
47            FFI_ExpressionPlacement::KeepInPlace => Self::KeepInPlace,
48        }
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use datafusion::logical_expr::ExpressionPlacement;
55
56    use super::FFI_ExpressionPlacement;
57
58    fn test_round_trip_placement(placement: ExpressionPlacement) {
59        let ffi_placement: FFI_ExpressionPlacement = placement.into();
60        let round_trip: ExpressionPlacement = ffi_placement.into();
61
62        assert_eq!(placement, round_trip);
63    }
64
65    #[test]
66    fn test_all_round_trip_placement() {
67        test_round_trip_placement(ExpressionPlacement::Literal);
68        test_round_trip_placement(ExpressionPlacement::Column);
69        test_round_trip_placement(ExpressionPlacement::MoveTowardsLeafNodes);
70        test_round_trip_placement(ExpressionPlacement::KeepInPlace);
71    }
72}