Skip to content

Commit 420a862

Browse files
authored
Fix: Show backtrace for ArrowError (apache#17204)
* fix backtrace for ArrowError * Update datafusion-cli/tests/cli_integration.rs * fix tests
1 parent c17116f commit 420a862

5 files changed

Lines changed: 38 additions & 5 deletions

File tree

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ jobs:
322322
AWS_SECRET_ACCESS_KEY: TEST-DataFusionPassword
323323
TEST_STORAGE_INTEGRATION: 1
324324
AWS_ALLOW_HTTP: true
325-
run: cargo test --profile ci -p datafusion-cli --lib --tests --bins
325+
run: cargo test --features backtrace --profile ci -p datafusion-cli --lib --tests --bins
326326
- name: Verify Working Directory Clean
327327
run: git diff --exit-code
328328

datafusion-cli/tests/cli_integration.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,30 @@ SELECT COUNT(*) FROM hits;
332332
.env_remove("AWS_ENDPOINT")
333333
.pass_stdin(input));
334334
}
335+
336+
/// Ensure backtrace will be printed, if executing `datafusion-cli` with a query
337+
/// that triggers error.
338+
/// Example:
339+
/// RUST_BACKTRACE=1 cargo run --features backtrace -- -c 'select pow(1,'foo');'
340+
#[rstest]
341+
#[case("SELECT pow(1,'foo')")]
342+
#[case("SELECT CAST('not_a_number' AS INTEGER);")]
343+
fn test_backtrace_output(#[case] query: &str) {
344+
let mut cmd = cli();
345+
// Use a command that will cause an error and trigger backtrace
346+
cmd.args(["--command", query, "-q"])
347+
.env("RUST_BACKTRACE", "1"); // Enable backtrace
348+
349+
let output = cmd.output().expect("Failed to execute command");
350+
let stdout = String::from_utf8_lossy(&output.stdout);
351+
let stderr = String::from_utf8_lossy(&output.stderr);
352+
let combined_output = format!("{}{}", stdout, stderr);
353+
354+
// Assert that the output includes literal 'backtrace'
355+
assert!(
356+
combined_output.to_lowercase().contains("backtrace"),
357+
"Expected output to contain 'backtrace', but got stdout: '{}' stderr: '{}'",
358+
stdout,
359+
stderr
360+
);
361+
}

datafusion/common/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl From<io::Error> for DataFusionError {
276276

277277
impl From<ArrowError> for DataFusionError {
278278
fn from(e: ArrowError) -> Self {
279-
DataFusionError::ArrowError(Box::new(e), None)
279+
DataFusionError::ArrowError(Box::new(e), Some(DataFusionError::get_back_trace()))
280280
}
281281
}
282282

datafusion/core/src/datasource/file_format/arrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ mod tests {
515515
assert!(err.is_err());
516516
assert_eq!(
517517
"Arrow error: Parser error: Unexpected end of byte stream for Arrow IPC file",
518-
err.unwrap_err().to_string()
518+
err.unwrap_err().to_string().lines().next().unwrap()
519519
);
520520

521521
Ok(())

datafusion/spark/src/function/bitwise/bit_get.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,20 @@ mod tests {
234234
Arc::new(Int64Array::from(vec![11])),
235235
Arc::new(Int32Array::from(vec![-1])),
236236
]);
237-
assert_eq!(result.unwrap_err().message(), "Compute error: bit_get: position -1 is out of bounds. Expected pos < 64 and pos >= 0");
237+
assert_eq!(
238+
result.unwrap_err().message().lines().next().unwrap(),
239+
"Compute error: bit_get: position -1 is out of bounds. Expected pos < 64 and pos >= 0"
240+
);
238241

239242
let result = spark_bit_get(&[
240243
Arc::new(Int64Array::from(vec![11])),
241244
Arc::new(Int32Array::from(vec![64])),
242245
]);
243246

244-
assert_eq!(result.unwrap_err().message(), "Compute error: bit_get: position 64 is out of bounds. Expected pos < 64 and pos >= 0");
247+
assert_eq!(
248+
result.unwrap_err().message().lines().next().unwrap(),
249+
"Compute error: bit_get: position 64 is out of bounds. Expected pos < 64 and pos >= 0"
250+
);
245251
}
246252

247253
#[test]

0 commit comments

Comments
 (0)