1#![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#![deny(clippy::clone_on_ref_ptr)]
26
27mod column;
28mod dfschema;
29mod functional_dependencies;
30mod join_type;
31mod param_value;
32#[cfg(feature = "pyarrow")]
33mod pyarrow;
34mod schema_reference;
35mod table_reference;
36mod unnest;
37
38pub mod alias;
39pub mod cast;
40pub mod config;
41pub mod cse;
42pub mod datatype;
43pub mod diagnostic;
44pub mod display;
45pub mod encryption;
46pub mod error;
47pub mod file_options;
48pub mod format;
49pub mod hash_utils;
50pub mod instant;
51pub mod metadata;
52pub mod nested_struct;
53mod null_equality;
54pub mod parsers;
55pub mod pruning;
56pub mod rounding;
57pub mod scalar;
58pub mod spans;
59pub mod stats;
60pub mod test_util;
61pub mod tree_node;
62pub mod types;
63pub mod utils;
64
65pub use arrow;
67pub use column::Column;
68pub use dfschema::{
69 qualified_name, DFSchema, DFSchemaRef, ExprSchema, SchemaExt, ToDFSchema,
70};
71pub use diagnostic::Diagnostic;
72pub use error::{
73 field_not_found, unqualified_field_not_found, DataFusionError, Result, SchemaError,
74 SharedResult,
75};
76pub use file_options::file_type::{
77 GetExt, DEFAULT_ARROW_EXTENSION, DEFAULT_AVRO_EXTENSION, DEFAULT_CSV_EXTENSION,
78 DEFAULT_JSON_EXTENSION, DEFAULT_PARQUET_EXTENSION,
79};
80pub use functional_dependencies::{
81 aggregate_functional_dependencies, get_required_group_by_exprs_indices,
82 get_target_functional_dependencies, Constraint, Constraints, Dependency,
83 FunctionalDependence, FunctionalDependencies,
84};
85use hashbrown::hash_map::DefaultHashBuilder;
86pub use join_type::{JoinConstraint, JoinSide, JoinType};
87pub use nested_struct::cast_column;
88pub use null_equality::NullEquality;
89pub use param_value::ParamValues;
90pub use scalar::{ScalarType, ScalarValue};
91pub use schema_reference::SchemaReference;
92pub use spans::{Location, Span, Spans};
93pub use stats::{ColumnStatistics, Statistics};
94pub use table_reference::{ResolvedTableReference, TableReference};
95pub use unnest::{RecursionUnnestOption, UnnestOptions};
96pub use utils::project_schema;
97
98#[doc(hidden)]
104pub use error::{
105 _config_datafusion_err, _exec_datafusion_err, _internal_datafusion_err,
106 _not_impl_datafusion_err, _plan_datafusion_err, _resources_datafusion_err,
107 _substrait_datafusion_err,
108};
109
110pub type HashMap<K, V, S = DefaultHashBuilder> = hashbrown::HashMap<K, V, S>;
112pub type HashSet<T, S = DefaultHashBuilder> = hashbrown::HashSet<T, S>;
113pub mod hash_map {
114 pub use hashbrown::hash_map::Entry;
115}
116pub mod hash_set {
117 pub use hashbrown::hash_set::Entry;
118}
119
120pub use hashbrown;
121
122#[macro_export]
127macro_rules! downcast_value {
128 ($Value: expr, $Type: ident) => {{
129 use $crate::__private::DowncastArrayHelper;
130 $Value.downcast_array_helper::<$Type>()?
131 }};
132 ($Value: expr, $Type: ident, $T: tt) => {{
133 use $crate::__private::DowncastArrayHelper;
134 $Value.downcast_array_helper::<$Type<$T>>()?
135 }};
136}
137
138#[doc(hidden)]
140pub mod __private {
141 use crate::error::_internal_datafusion_err;
142 use crate::Result;
143 use arrow::array::Array;
144 use std::any::{type_name, Any};
145
146 #[doc(hidden)]
147 pub trait DowncastArrayHelper {
148 fn downcast_array_helper<U: Any>(&self) -> Result<&U>;
149 }
150
151 impl<T: Array + ?Sized> DowncastArrayHelper for T {
152 fn downcast_array_helper<U: Any>(&self) -> Result<&U> {
153 self.as_any().downcast_ref().ok_or_else(|| {
154 let actual_type = self.data_type();
155 let desired_type_name = type_name::<U>();
156 _internal_datafusion_err!(
157 "could not cast array of type {} to {}",
158 actual_type,
159 desired_type_name
160 )
161 })
162 }
163 }
164}
165
166#[cfg(test)]
167mod tests {
168 use arrow::array::{ArrayRef, Int32Array, UInt64Array};
169 use std::any::{type_name, type_name_of_val};
170 use std::sync::Arc;
171
172 #[test]
173 fn test_downcast_value() -> crate::Result<()> {
174 let boxed: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3]));
175 let array = downcast_value!(&boxed, Int32Array);
176 assert_eq!(type_name_of_val(&array), type_name::<&Int32Array>());
177
178 let expected: Int32Array = vec![1, 2, 3].into_iter().map(Some).collect();
179 assert_eq!(array, &expected);
180 Ok(())
181 }
182
183 #[test]
184 fn test_downcast_value_err_message() {
185 let boxed: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3]));
186 let error: crate::DataFusionError = (|| {
187 downcast_value!(&boxed, UInt64Array);
188 Ok(())
189 })()
190 .err()
191 .unwrap();
192
193 assert_starts_with(
194 error.to_string(),
195 "Internal error: could not cast array of type Int32 to arrow_array::array::primitive_array::PrimitiveArray<arrow_array::types::UInt64Type>"
196 );
197 }
198
199 fn assert_starts_with(actual: impl AsRef<str>, expected_prefix: impl AsRef<str>) {
202 let actual = actual.as_ref();
203 let expected_prefix = expected_prefix.as_ref();
204 assert!(
205 actual.starts_with(expected_prefix),
206 "Expected '{actual}' to start with '{expected_prefix}'"
207 );
208 }
209}