Skip to content

Commit 880b94f

Browse files
author
Jiayu Liu
committed
fix unit test
1 parent 4e792e1 commit 880b94f

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

datafusion/src/physical_plan/window_functions.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ mod tests {
225225
WindowFunction::AggregateFunction(AggregateFunction::Avg)
226226
);
227227
assert_eq!(
228-
WindowFunction::from_str("cum_dist")?,
228+
WindowFunction::from_str("cume_dist")?,
229229
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::CumeDist)
230230
);
231231
assert_eq!(
@@ -253,6 +253,9 @@ mod tests {
253253
let observed = return_type(&fun, &[DataType::Utf8])?;
254254
assert_eq!(DataType::UInt64, observed);
255255

256+
let observed = return_type(&fun, &[DataType::UInt64])?;
257+
assert_eq!(DataType::UInt64, observed);
258+
256259
Ok(())
257260
}
258261

@@ -262,6 +265,9 @@ mod tests {
262265
let observed = return_type(&fun, &[DataType::Utf8])?;
263266
assert_eq!(DataType::Utf8, observed);
264267

268+
let observed = return_type(&fun, &[DataType::UInt64])?;
269+
assert_eq!(DataType::UInt64, observed);
270+
265271
Ok(())
266272
}
267273

@@ -271,6 +277,9 @@ mod tests {
271277
let observed = return_type(&fun, &[DataType::Utf8])?;
272278
assert_eq!(DataType::Utf8, observed);
273279

280+
let observed = return_type(&fun, &[DataType::Float64])?;
281+
assert_eq!(DataType::Float64, observed);
282+
274283
Ok(())
275284
}
276285

@@ -280,6 +289,9 @@ mod tests {
280289
let observed = return_type(&fun, &[DataType::Utf8])?;
281290
assert_eq!(DataType::Utf8, observed);
282291

292+
let observed = return_type(&fun, &[DataType::Float64])?;
293+
assert_eq!(DataType::Float64, observed);
294+
283295
Ok(())
284296
}
285297

@@ -289,22 +301,28 @@ mod tests {
289301
let observed = return_type(&fun, &[DataType::Utf8])?;
290302
assert_eq!(DataType::Utf8, observed);
291303

304+
let observed = return_type(&fun, &[DataType::Float64])?;
305+
assert_eq!(DataType::Float64, observed);
306+
292307
Ok(())
293308
}
294309

295310
#[test]
296311
fn test_nth_value_return_type() -> Result<()> {
297312
let fun = WindowFunction::from_str("nth_value")?;
298-
let observed = return_type(&fun, &[DataType::Utf8])?;
313+
let observed = return_type(&fun, &[DataType::Utf8, DataType::UInt64])?;
299314
assert_eq!(DataType::Utf8, observed);
300315

316+
let observed = return_type(&fun, &[DataType::Float64, DataType::UInt64])?;
317+
assert_eq!(DataType::Float64, observed);
318+
301319
Ok(())
302320
}
303321

304322
#[test]
305323
fn test_cume_dist_return_type() -> Result<()> {
306324
let fun = WindowFunction::from_str("cume_dist")?;
307-
let observed = return_type(&fun, &[DataType::Float64])?;
325+
let observed = return_type(&fun, &[])?;
308326
assert_eq!(DataType::Float64, observed);
309327

310328
Ok(())

datafusion/src/sql/planner.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,10 +2722,11 @@ mod tests {
27222722

27232723
#[test]
27242724
fn empty_over_multiple() {
2725-
let sql = "SELECT order_id, MAX(qty) OVER (), CUMe_dist(qty), lag(qty) OVER () from orders";
2725+
let sql =
2726+
"SELECT order_id, MAX(qty) OVER (), min(qty) over (), aVg(qty) OVER () from orders";
27262727
let expected = "\
2727-
Projection: #order_id, #MAX(qty Multiply Float64(1.1))\
2728-
\n WindowAggr: windowExpr=[[MAX(#qty Multiply Float64(1.1))]] partitionBy=[], orderBy=[]\
2728+
Projection: #order_id, #MAX(qty), #MIN(qty), #AVG(qty)\
2729+
\n WindowAggr: windowExpr=[[MAX(#qty), MIN(#qty), AVG(#qty)]] partitionBy=[], orderBy=[]\
27292730
\n TableScan: orders projection=None";
27302731
quick_test(sql, expected);
27312732
}

datafusion/tests/sql.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,20 @@ async fn csv_query_count() -> Result<()> {
797797
Ok(())
798798
}
799799

800+
#[tokio::test]
801+
async fn csv_query_window_with_empty_over() -> Result<()> {
802+
let mut ctx = ExecutionContext::new();
803+
register_aggregate_csv(&mut ctx)?;
804+
let sql = "SELECT count(c12) over () FROM aggregate_test_100";
805+
let actual = execute(&mut ctx, sql).await;
806+
// FIXME: so far the WindowAggExec is not implemented
807+
// and the current behavior is to return empty result
808+
// when it is done this test shall be updated
809+
let expected: Vec<Vec<String>> = vec![];
810+
assert_eq!(expected, actual);
811+
Ok(())
812+
}
813+
800814
#[tokio::test]
801815
async fn csv_query_group_by_int_count() -> Result<()> {
802816
let mut ctx = ExecutionContext::new();

0 commit comments

Comments
 (0)