datafusion_ffi/
table_source.rs1use abi_stable::StableAbi;
19use datafusion_expr::{TableProviderFilterPushDown, TableType};
20
21#[repr(C)]
23#[derive(StableAbi)]
24pub enum FFI_TableProviderFilterPushDown {
25 Unsupported,
26 Inexact,
27 Exact,
28}
29
30impl From<&FFI_TableProviderFilterPushDown> for TableProviderFilterPushDown {
31 fn from(value: &FFI_TableProviderFilterPushDown) -> Self {
32 match value {
33 FFI_TableProviderFilterPushDown::Unsupported => {
34 TableProviderFilterPushDown::Unsupported
35 }
36 FFI_TableProviderFilterPushDown::Inexact => {
37 TableProviderFilterPushDown::Inexact
38 }
39 FFI_TableProviderFilterPushDown::Exact => TableProviderFilterPushDown::Exact,
40 }
41 }
42}
43
44impl From<&TableProviderFilterPushDown> for FFI_TableProviderFilterPushDown {
45 fn from(value: &TableProviderFilterPushDown) -> Self {
46 match value {
47 TableProviderFilterPushDown::Unsupported => {
48 FFI_TableProviderFilterPushDown::Unsupported
49 }
50 TableProviderFilterPushDown::Inexact => {
51 FFI_TableProviderFilterPushDown::Inexact
52 }
53 TableProviderFilterPushDown::Exact => FFI_TableProviderFilterPushDown::Exact,
54 }
55 }
56}
57
58#[repr(C)]
60#[derive(Debug, Clone, Copy, PartialEq, Eq, StableAbi)]
61pub enum FFI_TableType {
62 Base,
63 View,
64 Temporary,
65}
66
67impl From<FFI_TableType> for TableType {
68 fn from(value: FFI_TableType) -> Self {
69 match value {
70 FFI_TableType::Base => TableType::Base,
71 FFI_TableType::View => TableType::View,
72 FFI_TableType::Temporary => TableType::Temporary,
73 }
74 }
75}
76
77impl From<TableType> for FFI_TableType {
78 fn from(value: TableType) -> Self {
79 match value {
80 TableType::Base => FFI_TableType::Base,
81 TableType::View => FFI_TableType::View,
82 TableType::Temporary => FFI_TableType::Temporary,
83 }
84 }
85}
86
87#[cfg(test)]
88mod tests {
89 use datafusion::error::Result;
90
91 use super::*;
92
93 fn round_trip_filter_pushdown(pushdown: TableProviderFilterPushDown) -> Result<()> {
94 let ffi_pushdown: FFI_TableProviderFilterPushDown = (&pushdown).into();
95 let round_trip: TableProviderFilterPushDown = (&ffi_pushdown).into();
96
97 assert_eq!(pushdown, round_trip);
98 Ok(())
99 }
100
101 #[test]
102 fn round_trip_all_filter_pushdowns() -> Result<()> {
103 round_trip_filter_pushdown(TableProviderFilterPushDown::Exact)?;
104 round_trip_filter_pushdown(TableProviderFilterPushDown::Inexact)?;
105 round_trip_filter_pushdown(TableProviderFilterPushDown::Unsupported)?;
106
107 Ok(())
108 }
109
110 fn round_trip_table_type(table_type: TableType) -> Result<()> {
111 let ffi_type: FFI_TableType = table_type.into();
112 let round_trip_type: TableType = ffi_type.into();
113
114 assert_eq!(table_type, round_trip_type);
115 Ok(())
116 }
117
118 #[test]
119 fn test_round_all_trip_table_type() -> Result<()> {
120 round_trip_table_type(TableType::Base)?;
121 round_trip_table_type(TableType::Temporary)?;
122 round_trip_table_type(TableType::View)?;
123
124 Ok(())
125 }
126}