Apache DataFusion SQL Query Engine
Fix: Show backtrace for ArrowError (#17204)
Yongting You420a862faa98
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.ymlindex 2ec1ee7c0f..25ab0a6c6f 100644--- a/.github/workflows/rust.yml+++ b/.github/workflows/rust.yml@@ -322,7 +322,7 @@ jobs:AWS_SECRET_ACCESS_KEY: TEST-DataFusionPasswordTEST_STORAGE_INTEGRATION: 1AWS_ALLOW_HTTP: true- run: cargo test --profile ci -p datafusion-cli --lib --tests --bins+ run: cargo test --features backtrace --profile ci -p datafusion-cli --lib --tests --bins- name: Verify Working Directory Cleanrun: git diff --exit-codediff --git a/datafusion-cli/tests/cli_integration.rs b/datafusion-cli/tests/cli_integration.rsindex 1b937ea216..a63dd3945a 100644--- a/datafusion-cli/tests/cli_integration.rs+++ b/datafusion-cli/tests/cli_integration.rs@@ -332,3 +332,30 @@ SELECT COUNT(*) FROM hits;.env_remove("AWS_ENDPOINT").pass_stdin(input));}++/// Ensure backtrace will be printed, if executing `datafusion-cli` with a query+/// that triggers error.+/// Example:+/// RUST_BACKTRACE=1 cargo run --features backtrace -- -c 'select pow(1,'foo');'+#[rstest]+#[case("SELECT pow(1,'foo')")]+#[case("SELECT CAST('not_a_number' AS INTEGER);")]+fn test_backtrace_output(#[case] query: &str) {+ let mut cmd = cli();+ // Use a command that will cause an error and trigger backtrace+ cmd.args(["--command", query, "-q"])+ .env("RUST_BACKTRACE", "1"); // Enable backtrace++ let output = cmd.output().expect("Failed to execute command");+ let stdout = String::from_utf8_lossy(&output.stdout);+ let stderr = String::from_utf8_lossy(&output.stderr);+ let combined_output = format!("{}{}", stdout, stderr);++ // Assert that the output includes literal 'backtrace'+ assert!(+ combined_output.to_lowercase().contains("backtrace"),+ "Expected output to contain 'backtrace', but got stdout: '{}' stderr: '{}'",+ stdout,+ stderr+ );+}diff --git a/datafusion/common/src/error.rs b/datafusion/common/src/error.rsindex d08d2394e4..8b64c0a6a4 100644--- a/datafusion/common/src/error.rs+++ b/datafusion/common/src/error.rs@@ -276,7 +276,7 @@ impl From<io::Error> for DataFusionError {impl From<ArrowError> for DataFusionError {fn from(e: ArrowError) -> Self {- DataFusionError::ArrowError(Box::new(e), None)+ DataFusionError::ArrowError(Box::new(e), Some(DataFusionError::get_back_trace()))}}diff --git a/datafusion/core/src/datasource/file_format/arrow.rs b/datafusion/core/src/datasource/file_format/arrow.rsindex 19e884601c..5ce70e3284 100644--- a/datafusion/core/src/datasource/file_format/arrow.rs+++ b/datafusion/core/src/datasource/file_format/arrow.rs@@ -515,7 +515,7 @@ mod tests {assert!(err.is_err());assert_eq!("Arrow error: Parser error: Unexpected end of byte stream for Arrow IPC file",- err.unwrap_err().to_string()+ err.unwrap_err().to_string().lines().next().unwrap());Ok(())diff --git a/datafusion/spark/src/function/bitwise/bit_get.rs b/datafusion/spark/src/function/bitwise/bit_get.rsindex 89803b6f50..a8562618cb 100644--- a/datafusion/spark/src/function/bitwise/bit_get.rs+++ b/datafusion/spark/src/function/bitwise/bit_get.rs@@ -234,14 +234,20 @@ mod tests {Arc::new(Int64Array::from(vec![11])),Arc::new(Int32Array::from(vec![-1])),]);- assert_eq!(result.unwrap_err().message(), "Compute error: bit_get: position -1 is out of bounds. Expected pos < 64 and pos >= 0");+ assert_eq!(+ result.unwrap_err().message().lines().next().unwrap(),+ "Compute error: bit_get: position -1 is out of bounds. Expected pos < 64 and pos >= 0"+ );let result = spark_bit_get(&[Arc::new(Int64Array::from(vec![11])),Arc::new(Int32Array::from(vec![64])),]);- assert_eq!(result.unwrap_err().message(), "Compute error: bit_get: position 64 is out of bounds. Expected pos < 64 and pos >= 0");+ assert_eq!(+ result.unwrap_err().message().lines().next().unwrap(),+ "Compute error: bit_get: position 64 is out of bounds. Expected pos < 64 and pos >= 0"+ );}#[test]