From 880b94f6e27df61b4d3877366f71a51b9b2f5d5d Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Fri, 21 May 2021 08:24:00 +0800 Subject: [PATCH] fix unit test --- .../src/physical_plan/window_functions.rs | 24 ++++++++++++++++--- datafusion/src/sql/planner.rs | 7 +++--- datafusion/tests/sql.rs | 14 +++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/datafusion/src/physical_plan/window_functions.rs b/datafusion/src/physical_plan/window_functions.rs index 02ef3f15eaad..91e1f379f5f0 100644 --- a/datafusion/src/physical_plan/window_functions.rs +++ b/datafusion/src/physical_plan/window_functions.rs @@ -225,7 +225,7 @@ mod tests { WindowFunction::AggregateFunction(AggregateFunction::Avg) ); assert_eq!( - WindowFunction::from_str("cum_dist")?, + WindowFunction::from_str("cume_dist")?, WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::CumeDist) ); assert_eq!( @@ -253,6 +253,9 @@ mod tests { let observed = return_type(&fun, &[DataType::Utf8])?; assert_eq!(DataType::UInt64, observed); + let observed = return_type(&fun, &[DataType::UInt64])?; + assert_eq!(DataType::UInt64, observed); + Ok(()) } @@ -262,6 +265,9 @@ mod tests { let observed = return_type(&fun, &[DataType::Utf8])?; assert_eq!(DataType::Utf8, observed); + let observed = return_type(&fun, &[DataType::UInt64])?; + assert_eq!(DataType::UInt64, observed); + Ok(()) } @@ -271,6 +277,9 @@ mod tests { let observed = return_type(&fun, &[DataType::Utf8])?; assert_eq!(DataType::Utf8, observed); + let observed = return_type(&fun, &[DataType::Float64])?; + assert_eq!(DataType::Float64, observed); + Ok(()) } @@ -280,6 +289,9 @@ mod tests { let observed = return_type(&fun, &[DataType::Utf8])?; assert_eq!(DataType::Utf8, observed); + let observed = return_type(&fun, &[DataType::Float64])?; + assert_eq!(DataType::Float64, observed); + Ok(()) } @@ -289,22 +301,28 @@ mod tests { let observed = return_type(&fun, &[DataType::Utf8])?; assert_eq!(DataType::Utf8, observed); + let observed = return_type(&fun, &[DataType::Float64])?; + assert_eq!(DataType::Float64, observed); + Ok(()) } #[test] fn test_nth_value_return_type() -> Result<()> { let fun = WindowFunction::from_str("nth_value")?; - let observed = return_type(&fun, &[DataType::Utf8])?; + let observed = return_type(&fun, &[DataType::Utf8, DataType::UInt64])?; assert_eq!(DataType::Utf8, observed); + let observed = return_type(&fun, &[DataType::Float64, DataType::UInt64])?; + assert_eq!(DataType::Float64, observed); + Ok(()) } #[test] fn test_cume_dist_return_type() -> Result<()> { let fun = WindowFunction::from_str("cume_dist")?; - let observed = return_type(&fun, &[DataType::Float64])?; + let observed = return_type(&fun, &[])?; assert_eq!(DataType::Float64, observed); Ok(()) diff --git a/datafusion/src/sql/planner.rs b/datafusion/src/sql/planner.rs index df7e0ce982fc..a3027e589985 100644 --- a/datafusion/src/sql/planner.rs +++ b/datafusion/src/sql/planner.rs @@ -2722,10 +2722,11 @@ mod tests { #[test] fn empty_over_multiple() { - let sql = "SELECT order_id, MAX(qty) OVER (), CUMe_dist(qty), lag(qty) OVER () from orders"; + let sql = + "SELECT order_id, MAX(qty) OVER (), min(qty) over (), aVg(qty) OVER () from orders"; let expected = "\ - Projection: #order_id, #MAX(qty Multiply Float64(1.1))\ - \n WindowAggr: windowExpr=[[MAX(#qty Multiply Float64(1.1))]] partitionBy=[], orderBy=[]\ + Projection: #order_id, #MAX(qty), #MIN(qty), #AVG(qty)\ + \n WindowAggr: windowExpr=[[MAX(#qty), MIN(#qty), AVG(#qty)]] partitionBy=[], orderBy=[]\ \n TableScan: orders projection=None"; quick_test(sql, expected); } diff --git a/datafusion/tests/sql.rs b/datafusion/tests/sql.rs index 17e0f13609a3..5b56e76baca8 100644 --- a/datafusion/tests/sql.rs +++ b/datafusion/tests/sql.rs @@ -797,6 +797,20 @@ async fn csv_query_count() -> Result<()> { Ok(()) } +#[tokio::test] +async fn csv_query_window_with_empty_over() -> Result<()> { + let mut ctx = ExecutionContext::new(); + register_aggregate_csv(&mut ctx)?; + let sql = "SELECT count(c12) over () FROM aggregate_test_100"; + let actual = execute(&mut ctx, sql).await; + // FIXME: so far the WindowAggExec is not implemented + // and the current behavior is to return empty result + // when it is done this test shall be updated + let expected: Vec> = vec![]; + assert_eq!(expected, actual); + Ok(()) +} + #[tokio::test] async fn csv_query_group_by_int_count() -> Result<()> { let mut ctx = ExecutionContext::new();