Skip to content

Commit 149d3e9

Browse files
authored
chore: Extend backtrace coverage for Execution and Internal errors (#17921)
* chore: Extend backtrace coverage * fmt * part2 * doc * feedback * feedback * clippy * feedback
1 parent 307f5c3 commit 149d3e9

File tree

83 files changed

+473
-585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+473
-585
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion-cli/src/command.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ use clap::ValueEnum;
2626
use datafusion::arrow::array::{ArrayRef, StringArray};
2727
use datafusion::arrow::datatypes::{DataType, Field, Schema};
2828
use datafusion::arrow::record_batch::RecordBatch;
29-
use datafusion::common::exec_err;
3029
use datafusion::common::instant::Instant;
31-
use datafusion::error::{DataFusionError, Result};
30+
use datafusion::common::{exec_datafusion_err, exec_err};
31+
use datafusion::error::Result;
3232
use std::fs::File;
3333
use std::io::BufReader;
3434
use std::str::FromStr;
@@ -84,9 +84,7 @@ impl Command {
8484
Self::Include(filename) => {
8585
if let Some(filename) = filename {
8686
let file = File::open(filename).map_err(|e| {
87-
DataFusionError::Execution(format!(
88-
"Error opening {filename:?} {e}"
89-
))
87+
exec_datafusion_err!("Error opening {filename:?} {e}")
9088
})?;
9189
exec_from_lines(ctx, &mut BufReader::new(file), print_options)
9290
.await?;

datafusion-cli/src/object_storage.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,7 @@ pub fn get_gcs_object_store_builder(
295295

296296
fn get_bucket_name(url: &Url) -> Result<&str> {
297297
url.host_str().ok_or_else(|| {
298-
DataFusionError::Execution(format!(
299-
"Not able to parse bucket name from url: {}",
300-
url.as_str()
301-
))
298+
exec_datafusion_err!("Not able to parse bucket name from url: {}", url.as_str())
302299
})
303300
}
304301

datafusion-examples/examples/function_factory.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use arrow::datatypes::DataType;
1919
use datafusion::common::tree_node::{Transformed, TreeNode};
20-
use datafusion::common::{exec_err, internal_err, DataFusionError};
20+
use datafusion::common::{exec_datafusion_err, exec_err, internal_err, DataFusionError};
2121
use datafusion::error::Result;
2222
use datafusion::execution::context::{
2323
FunctionFactory, RegisterFunction, SessionContext, SessionState,
@@ -185,9 +185,7 @@ impl ScalarFunctionWrapper {
185185
fn parse_placeholder_identifier(placeholder: &str) -> Result<usize> {
186186
if let Some(value) = placeholder.strip_prefix('$') {
187187
Ok(value.parse().map(|v: usize| v - 1).map_err(|e| {
188-
DataFusionError::Execution(format!(
189-
"Placeholder `{placeholder}` parsing error: {e}!"
190-
))
188+
exec_datafusion_err!("Placeholder `{placeholder}` parsing error: {e}!")
191189
})?)
192190
} else {
193191
exec_err!("Placeholder should start with `$`!")

datafusion-examples/examples/json_shredding.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use datafusion::assert_batches_eq;
2525
use datafusion::common::tree_node::{
2626
Transformed, TransformedResult, TreeNode, TreeNodeRecursion,
2727
};
28-
use datafusion::common::{assert_contains, Result};
28+
use datafusion::common::{assert_contains, exec_datafusion_err, Result};
2929
use datafusion::datasource::listing::{
3030
ListingTable, ListingTableConfig, ListingTableUrl,
3131
};
@@ -230,8 +230,8 @@ impl ScalarUDFImpl for JsonGetStr {
230230
let key = match &args.args[0] {
231231
ColumnarValue::Scalar(ScalarValue::Utf8(Some(key))) => key,
232232
_ => {
233-
return Err(datafusion::error::DataFusionError::Execution(
234-
"json_get_str first argument must be a string".to_string(),
233+
return Err(exec_datafusion_err!(
234+
"json_get_str first argument must be a string"
235235
))
236236
}
237237
};
@@ -241,13 +241,13 @@ impl ScalarUDFImpl for JsonGetStr {
241241
.as_any()
242242
.downcast_ref::<StringArray>()
243243
.ok_or_else(|| {
244-
datafusion::error::DataFusionError::Execution(
245-
"json_get_str second argument must be a string array".to_string(),
244+
exec_datafusion_err!(
245+
"json_get_str second argument must be a string array"
246246
)
247247
})?,
248248
_ => {
249-
return Err(datafusion::error::DataFusionError::Execution(
250-
"json_get_str second argument must be a string array".to_string(),
249+
return Err(exec_datafusion_err!(
250+
"json_get_str second argument must be a string array"
251251
))
252252
}
253253
};

datafusion-examples/examples/memory_pool_execution_plan.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
use arrow::record_batch::RecordBatch;
2828
use arrow_schema::SchemaRef;
2929
use datafusion::common::record_batch;
30+
use datafusion::common::{exec_datafusion_err, internal_err};
3031
use datafusion::datasource::{memory::MemTable, DefaultTableSource};
31-
use datafusion::error::{DataFusionError, Result};
32+
use datafusion::error::Result;
3233
use datafusion::execution::memory_pool::{MemoryConsumer, MemoryReservation};
3334
use datafusion::execution::runtime_env::RuntimeEnvBuilder;
3435
use datafusion::execution::{SendableRecordBatchStream, TaskContext};
@@ -247,9 +248,7 @@ impl ExecutionPlan for BufferingExecutionPlan {
247248
children[0].clone(),
248249
)))
249250
} else {
250-
Err(DataFusionError::Internal(
251-
"BufferingExecutionPlan must have exactly one child".to_string(),
252-
))
251+
internal_err!("BufferingExecutionPlan must have exactly one child")
253252
}
254253
}
255254

@@ -289,9 +288,7 @@ impl ExecutionPlan for BufferingExecutionPlan {
289288
// In a real implementation, you would create a batch stream from the processed results
290289
record_batch!(("id", Int32, vec![5]), ("name", Utf8, vec!["Eve"]))
291290
.map_err(|e| {
292-
DataFusionError::Execution(format!(
293-
"Failed to create final RecordBatch: {e}",
294-
))
291+
exec_datafusion_err!("Failed to create final RecordBatch: {e}")
295292
})
296293
}),
297294
)))

datafusion/catalog/src/listing_schema.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ use std::sync::{Arc, Mutex};
2525
use crate::{SchemaProvider, TableProvider, TableProviderFactory};
2626

2727
use crate::Session;
28-
use datafusion_common::{DFSchema, DataFusionError, HashMap, TableReference};
28+
use datafusion_common::{
29+
internal_datafusion_err, DFSchema, DataFusionError, HashMap, TableReference,
30+
};
2931
use datafusion_expr::CreateExternalTable;
3032

3133
use async_trait::async_trait;
@@ -109,17 +111,13 @@ impl ListingSchemaProvider {
109111
let file_name = table
110112
.path
111113
.file_name()
112-
.ok_or_else(|| {
113-
DataFusionError::Internal("Cannot parse file name!".to_string())
114-
})?
114+
.ok_or_else(|| internal_datafusion_err!("Cannot parse file name!"))?
115115
.to_str()
116-
.ok_or_else(|| {
117-
DataFusionError::Internal("Cannot parse file name!".to_string())
118-
})?;
116+
.ok_or_else(|| internal_datafusion_err!("Cannot parse file name!"))?;
119117
let table_name = file_name.split('.').collect_vec()[0];
120-
let table_path = table.to_string().ok_or_else(|| {
121-
DataFusionError::Internal("Cannot parse file name!".to_string())
122-
})?;
118+
let table_path = table
119+
.to_string()
120+
.ok_or_else(|| internal_datafusion_err!("Cannot parse file name!"))?;
123121

124122
if !self.table_exist(table_name) {
125123
let table_url = format!("{}/{}", self.authority, table_path);

datafusion/common/src/utils/memory.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
//! This module provides a function to estimate the memory size of a HashTable prior to allocation
1919
20-
use crate::{DataFusionError, Result};
20+
use crate::error::_exec_datafusion_err;
21+
use crate::Result;
2122
use std::mem::size_of;
2223

2324
/// Estimates the memory size required for a hash table prior to allocation.
@@ -36,7 +37,7 @@ use std::mem::size_of;
3637
/// buckets.
3738
/// - One byte overhead for each bucket.
3839
/// - The fixed size overhead of the collection.
39-
/// - If the estimation overflows, we return a [`DataFusionError`]
40+
/// - If the estimation overflows, we return a [`crate::error::DataFusionError`]
4041
///
4142
/// # Examples
4243
/// ---
@@ -94,9 +95,7 @@ pub fn estimate_memory_size<T>(num_elements: usize, fixed_size: usize) -> Result
9495
.checked_add(fixed_size)
9596
})
9697
.ok_or_else(|| {
97-
DataFusionError::Execution(
98-
"usize overflow while estimating the number of buckets".to_string(),
99-
)
98+
_exec_datafusion_err!("usize overflow while estimating the number of buckets")
10099
})
101100
}
102101

datafusion/common/src/utils/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ pub mod memory;
2222
pub mod proxy;
2323
pub mod string_utils;
2424

25-
use crate::error::{_exec_datafusion_err, _internal_err};
26-
use crate::{DataFusionError, Result, ScalarValue};
25+
use crate::error::{_exec_datafusion_err, _internal_datafusion_err, _internal_err};
26+
use crate::{Result, ScalarValue};
2727
use arrow::array::{
2828
cast::AsArray, Array, ArrayRef, FixedSizeListArray, LargeListArray, ListArray,
2929
OffsetSizeTrait,
@@ -147,9 +147,7 @@ pub fn bisect<const SIDE: bool>(
147147
let low: usize = 0;
148148
let high: usize = item_columns
149149
.first()
150-
.ok_or_else(|| {
151-
DataFusionError::Internal("Column array shouldn't be empty".to_string())
152-
})?
150+
.ok_or_else(|| _internal_datafusion_err!("Column array shouldn't be empty"))?
153151
.len();
154152
let compare_fn = |current: &[ScalarValue], target: &[ScalarValue]| {
155153
let cmp = compare_rows(current, target, sort_options)?;
@@ -198,9 +196,7 @@ pub fn linear_search<const SIDE: bool>(
198196
let low: usize = 0;
199197
let high: usize = item_columns
200198
.first()
201-
.ok_or_else(|| {
202-
DataFusionError::Internal("Column array shouldn't be empty".to_string())
203-
})?
199+
.ok_or_else(|| _internal_datafusion_err!("Column array shouldn't be empty"))?
204200
.len();
205201
let compare_fn = |current: &[ScalarValue], target: &[ScalarValue]| {
206202
let cmp = compare_rows(current, target, sort_options)?;
@@ -365,9 +361,7 @@ pub fn get_at_indices<T: Clone, I: Borrow<usize>>(
365361
.map(|idx| items.get(*idx.borrow()).cloned())
366362
.collect::<Option<Vec<T>>>()
367363
.ok_or_else(|| {
368-
DataFusionError::Execution(
369-
"Expects indices to be in the range of searched vector".to_string(),
370-
)
364+
_exec_datafusion_err!("Expects indices to be in the range of searched vector")
371365
})
372366
}
373367

@@ -808,7 +802,7 @@ pub fn find_indices<T: PartialEq, S: Borrow<T>>(
808802
.into_iter()
809803
.map(|target| items.iter().position(|e| target.borrow().eq(e)))
810804
.collect::<Option<_>>()
811-
.ok_or_else(|| DataFusionError::Execution("Target not found".to_string()))
805+
.ok_or_else(|| _exec_datafusion_err!("Target not found"))
812806
}
813807

814808
/// Transposes the given vector of vectors.

datafusion/core/src/dataframe/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ use arrow::compute::{cast, concat};
5151
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
5252
use datafusion_common::config::{CsvOptions, JsonOptions};
5353
use datafusion_common::{
54-
exec_err, not_impl_err, plan_datafusion_err, plan_err, Column, DFSchema,
55-
DataFusionError, ParamValues, ScalarValue, SchemaError, TableReference,
56-
UnnestOptions,
54+
exec_err, internal_datafusion_err, not_impl_err, plan_datafusion_err, plan_err,
55+
Column, DFSchema, DataFusionError, ParamValues, ScalarValue, SchemaError,
56+
TableReference, UnnestOptions,
5757
};
5858
use datafusion_expr::select_expr::SelectExpr;
5959
use datafusion_expr::{
@@ -1347,9 +1347,9 @@ impl DataFrame {
13471347
.and_then(|r| r.columns().first())
13481348
.and_then(|c| c.as_any().downcast_ref::<Int64Array>())
13491349
.and_then(|a| a.values().first())
1350-
.ok_or(DataFusionError::Internal(
1351-
"Unexpected output when collecting for count()".to_string(),
1352-
))? as usize;
1350+
.ok_or_else(|| {
1351+
internal_datafusion_err!("Unexpected output when collecting for count()")
1352+
})? as usize;
13531353
Ok(len)
13541354
}
13551355

0 commit comments

Comments
 (0)