Skip to main content

datafusion_ffi/
lib.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
18#![doc(
19    html_logo_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg",
20    html_favicon_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg"
21)]
22#![cfg_attr(docsrs, feature(doc_cfg))]
23// Make sure fast / cheap clones on Arc are explicit:
24// https://github.com/apache/datafusion/issues/11143
25#![deny(clippy::clone_on_ref_ptr)]
26#![cfg_attr(test, allow(clippy::needless_pass_by_value))]
27
28pub mod arrow_wrappers;
29pub mod catalog_provider;
30pub mod catalog_provider_list;
31pub mod config;
32pub mod execution;
33pub mod execution_plan;
34pub mod expr;
35pub mod ffi_option;
36pub mod insert_op;
37pub mod physical_expr;
38pub mod physical_optimizer;
39pub mod plan_properties;
40pub mod proto;
41pub mod record_batch_stream;
42pub mod schema_provider;
43pub mod session;
44pub mod statistics;
45pub mod table_provider;
46pub mod table_provider_factory;
47pub mod table_source;
48pub mod udaf;
49pub mod udf;
50pub mod udtf;
51pub mod udwf;
52pub mod util;
53pub mod volatility;
54
55#[cfg(feature = "integration-tests")]
56pub mod tests;
57
58/// Returns the major version of the FFI implementation. If the API evolves,
59/// we use the major version to identify compatibility over the unsafe
60/// boundary. This call is intended to be used by implementers to validate
61/// they have compatible libraries.
62pub extern "C" fn version() -> u64 {
63    let version_str = env!("CARGO_PKG_VERSION");
64    let version = semver::Version::parse(version_str).expect("Invalid version string");
65    version.major
66}
67
68static LIBRARY_MARKER: u8 = 0;
69
70/// This utility is used to determine if two FFI structs are within
71/// the same library. It is possible that the interplay between
72/// foreign and local functions calls create one FFI struct that
73/// references another. It is helpful to determine if a foreign
74/// struct in the same library or called from a different one.
75/// If we are in the same library, then we can access the underlying
76/// types directly.
77///
78/// This function works by checking the address of the library
79/// marker. Each library that implements the FFI code will have
80/// a different address for the marker. By checking the marker
81/// address we can determine if a struct is truly foreign or is
82/// actually within the same originating library.
83///
84/// See the crate's `README.md` for additional information.
85pub extern "C" fn get_library_marker_id() -> usize {
86    &LIBRARY_MARKER as *const u8 as usize
87}
88
89/// For unit testing in this crate we need to trick the providers
90/// into thinking we have a foreign call. We do this by overwriting
91/// their `library_marker_id` function to return a different value.
92#[cfg(test)]
93pub(crate) extern "C" fn mock_foreign_marker_id() -> usize {
94    get_library_marker_id() + 1
95}
96
97#[cfg(doctest)]
98doc_comment::doctest!("../README.md", readme_example_test);