Apache DataFusion SQL Query Engine
minor: fix error type for window (#6231)
comphead6213a92e1a83
diff --git a/datafusion/core/src/physical_plan/planner.rs b/datafusion/core/src/physical_plan/planner.rsindex 2d616d5a7d..458b1b2a21 100644--- a/datafusion/core/src/physical_plan/planner.rs+++ b/datafusion/core/src/physical_plan/planner.rs@@ -1592,7 +1592,7 @@ pub fn create_window_expr_with_name(physical_input_schema,)}- other => Err(DataFusionError::Internal(format!(+ other => Err(DataFusionError::Plan(format!("Invalid window expression '{other:?}'"))),}diff --git a/datafusion/core/tests/sqllogictests/test_files/window.slt b/datafusion/core/tests/sqllogictests/test_files/window.sltindex 66b011eeb9..2027358f7c 100644--- a/datafusion/core/tests/sqllogictests/test_files/window.slt+++ b/datafusion/core/tests/sqllogictests/test_files/window.slt@@ -920,7 +920,7 @@ drop table temp#fn window_frame_ranges_unbounded_preceding_err-statement error DataFusion error: Execution error: Invalid window frame: end bound cannot be unbounded preceding+statement error DataFusion error: Error during planning: Invalid window frame: end bound cannot be unbounded precedingSELECTSUM(c2) OVER (ORDER BY c2 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED PRECEDING),COUNT(*) OVER (ORDER BY c2 RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED PRECEDING)@@ -2365,3 +2365,16 @@ SELECT c9, rn1 FROM (SELECT c9,4216440507 34144173353 44076864659 5+++# invalid window frame. null as preceding+statement error DataFusion error: Error during planning: Invalid window frame: frame offsets must be non negative integers+select row_number() over (rows between null preceding and current row) from (select 1 a) x++# invalid window frame. null as preceding+statement error DataFusion error: Error during planning: Invalid window frame: frame offsets must be non negative integers+select row_number() over (rows between null preceding and current row) from (select 1 a) x++# invalid window frame. negative as following+statement error DataFusion error: Error during planning: Invalid window frame: frame offsets must be non negative integers+select row_number() over (rows between current row and -1 following) from (select 1 a) xdiff --git a/datafusion/expr/src/window_frame.rs b/datafusion/expr/src/window_frame.rsindex 7794125d0e..97f767bfab 100644--- a/datafusion/expr/src/window_frame.rs+++ b/datafusion/expr/src/window_frame.rs@@ -68,14 +68,14 @@ impl TryFrom<ast::WindowFrame> for WindowFrame {if let WindowFrameBound::Following(val) = &start_bound {if val.is_null() {- return Err(DataFusionError::Execution(+ return Err(DataFusionError::Plan("Invalid window frame: start bound cannot be unbounded following".to_owned(),));}} else if let WindowFrameBound::Preceding(val) = &end_bound {if val.is_null() {- return Err(DataFusionError::Execution(+ return Err(DataFusionError::Plan("Invalid window frame: end bound cannot be unbounded preceding".to_owned(),));@@ -256,9 +256,11 @@ pub fn convert_frame_bound_to_scalar_value(v: ast::Expr) -> Result<ScalarValue>result}}- e => {- let msg = format!("Window frame bound cannot be {e:?}");- return Err(DataFusionError::Internal(msg));+ _ => {+ return Err(DataFusionError::Plan(+ "Invalid window frame: frame offsets must be non negative integers"+ .to_owned(),+ ));}})))}@@ -338,7 +340,7 @@ mod tests {let err = WindowFrame::try_from(window_frame).unwrap_err();assert_eq!(err.to_string(),- "Execution error: Invalid window frame: start bound cannot be unbounded following".to_owned()+ "Error during planning: Invalid window frame: start bound cannot be unbounded following".to_owned());let window_frame = ast::WindowFrame {@@ -349,7 +351,7 @@ mod tests {let err = WindowFrame::try_from(window_frame).unwrap_err();assert_eq!(err.to_string(),- "Execution error: Invalid window frame: end bound cannot be unbounded preceding".to_owned()+ "Error during planning: Invalid window frame: end bound cannot be unbounded preceding".to_owned());let window_frame = ast::WindowFrame {