From d79e37ad78b9053cdcfbddd6ce59665a358de2d9 Mon Sep 17 00:00:00 2001 From: remzi <13716567376yh@gmail.com> Date: Sun, 12 Feb 2023 11:35:15 +0800 Subject: [PATCH 1/2] enhance the test Signed-off-by: remzi <13716567376yh@gmail.com> --- datafusion/core/tests/sql/window.rs | 54 ++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/datafusion/core/tests/sql/window.rs b/datafusion/core/tests/sql/window.rs index 21a6062b8cd7a..21b92ed27e611 100644 --- a/datafusion/core/tests/sql/window.rs +++ b/datafusion/core/tests/sql/window.rs @@ -1464,22 +1464,50 @@ async fn window_frame_creation() -> Result<()> { "Execution error: Invalid window frame: start bound (2 FOLLOWING) cannot be larger than end bound (1 FOLLOWING)" ); - let df = ctx - .sql( - "SELECT - COUNT(c1) OVER (ORDER BY c2 RANGE BETWEEN '1 DAY' PRECEDING AND '2 DAY' FOLLOWING) - FROM aggregate_test_100;", - ) - .await?; - let results = df.collect().await; - assert_contains!( - results.err().unwrap().to_string(), - "External error: Internal error: Operator - is not implemented for types UInt32(1) and Utf8(\"1 DAY\"). This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker" - ); - Ok(()) } +#[tokio::test] +async fn window_frame_creation_type_checking() -> Result<()> { + // The following query has type error. We should test the error could be detected + // from either the logical plan (when `skip_failed_rules` is set to `false`) or + // the physical plan (when `skip_failed_rules` is set to `true`). + + // We should remove the type checking in physical plan after we don't skip + // the failed optimizing rules by default. (see more in https://github.com/apache/arrow-datafusion/issues/4615) + async fn check_query(skip_failed_rules: bool, err_msg: &str) -> Result<()> { + use datafusion_common::ScalarValue::Boolean; + let config = SessionConfig::new().set( + "datafusion.optimizer.skip_failed_rules", + Boolean(Some(skip_failed_rules)), + ); + let ctx = SessionContext::with_config(config); + register_aggregate_csv(&ctx).await?; + let df = ctx + .sql( + "SELECT + COUNT(c1) OVER (ORDER BY c2 RANGE BETWEEN '1 DAY' PRECEDING AND '2 DAY' FOLLOWING) + FROM aggregate_test_100;", + ) + .await?; + let results = df.collect().await; + assert_contains!(results.err().unwrap().to_string(), err_msg); + Ok(()) + } + + // error is return from physical plan + check_query( + true, + "External error: Internal error: Operator - is not implemented for types UInt32(1) and Utf8(\"1 DAY\")." + ).await?; + + // error is return from logical plan + check_query( + false, + "Internal error: Optimizer rule 'type_coercion' failed due to unexpected error: Arrow error: Cast error: Cannot cast string '1 DAY' to value of UInt32 type" + ).await +} + #[tokio::test] async fn test_window_row_number_aggregate() -> Result<()> { let config = SessionConfig::new(); From df5cda03357dcfc19c6a9114a9f3cce4acc38e73 Mon Sep 17 00:00:00 2001 From: remzi <13716567376yh@gmail.com> Date: Mon, 13 Feb 2023 10:43:34 +0800 Subject: [PATCH 2/2] update comment Signed-off-by: remzi <13716567376yh@gmail.com> --- datafusion/core/tests/sql/window.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datafusion/core/tests/sql/window.rs b/datafusion/core/tests/sql/window.rs index 9b9e1a9ee0ba6..af03d922c315b 100644 --- a/datafusion/core/tests/sql/window.rs +++ b/datafusion/core/tests/sql/window.rs @@ -1495,13 +1495,13 @@ async fn window_frame_creation_type_checking() -> Result<()> { Ok(()) } - // error is return from physical plan + // Error is returned from the physical plan. check_query( true, "Internal error: Operator - is not implemented for types UInt32(1) and Utf8(\"1 DAY\")." ).await?; - // error is return from logical plan + // Error is returned from the logical plan. check_query( false, "Internal error: Optimizer rule 'type_coercion' failed due to unexpected error: Arrow error: Cast error: Cannot cast string '1 DAY' to value of UInt32 type"