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