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