Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiayu Liu committed May 21, 2021
1 parent 4e792e1 commit 880b94f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
24 changes: 21 additions & 3 deletions datafusion/src/physical_plan/window_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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(())
}

Expand All @@ -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(())
}

Expand All @@ -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(())
}

Expand All @@ -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(())
}

Expand All @@ -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(())
Expand Down
7 changes: 4 additions & 3 deletions datafusion/src/sql/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 14 additions & 0 deletions datafusion/tests/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>> = vec![];
assert_eq!(expected, actual);
Ok(())
}

#[tokio::test]
async fn csv_query_group_by_int_count() -> Result<()> {
let mut ctx = ExecutionContext::new();
Expand Down

0 comments on commit 880b94f

Please sign in to comment.