Skip to content

Commit a1eae86

Browse files
author
Jiayu Liu
committed
enrich unit test
1 parent 0d2a214 commit a1eae86

File tree

1 file changed

+100
-1
lines changed

1 file changed

+100
-1
lines changed

datafusion/src/physical_plan/window_functions.rs

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,36 @@ fn signature(fun: &WindowFunction) -> Signature {
178178
#[cfg(test)]
179179
mod tests {
180180
use super::*;
181-
use arrow::datatypes::{DataType, Field};
181+
182+
#[test]
183+
fn test_window_function_from_str_to_str_round_trip_eq() -> Result<()> {
184+
let names = vec![
185+
"row_number",
186+
"rank",
187+
"dense_rank",
188+
"percent_rank",
189+
"cume_dist",
190+
"ntile",
191+
"lag",
192+
"lead",
193+
"first_value",
194+
"last_value",
195+
"nth_value",
196+
"min",
197+
"max",
198+
"count",
199+
"avg",
200+
"sum",
201+
];
202+
for name in names {
203+
let fun = WindowFunction::from_str(name)?;
204+
assert_eq!(fun.to_string(), name.to_uppercase());
205+
206+
let fun2 = WindowFunction::from_str(name.to_uppercase().as_str())?;
207+
assert_eq!(fun, fun2);
208+
}
209+
Ok(())
210+
}
182211

183212
#[test]
184213
fn test_window_function_from_str() -> Result<()> {
@@ -198,6 +227,76 @@ mod tests {
198227
WindowFunction::from_str("cum_dist")?,
199228
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::CumeDist)
200229
);
230+
assert_eq!(
231+
WindowFunction::from_str("first_value")?,
232+
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::FirstValue)
233+
);
234+
assert_eq!(
235+
WindowFunction::from_str("LAST_value")?,
236+
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::LastValue)
237+
);
238+
assert_eq!(
239+
WindowFunction::from_str("LAG")?,
240+
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::Lag)
241+
);
242+
assert_eq!(
243+
WindowFunction::from_str("LEAD")?,
244+
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::Lead)
245+
);
246+
Ok(())
247+
}
248+
249+
#[test]
250+
fn test_count_return_type() -> Result<()> {
251+
let fun = WindowFunction::from_str("count")?;
252+
let observed = return_type(&fun, &[DataType::Utf8])?;
253+
assert_eq!(DataType::UInt64, observed);
254+
255+
Ok(())
256+
}
257+
258+
#[test]
259+
fn test_first_value_return_type() -> Result<()> {
260+
let fun = WindowFunction::from_str("first_value")?;
261+
let observed = return_type(&fun, &[DataType::Utf8])?;
262+
assert_eq!(DataType::Utf8, observed);
263+
264+
Ok(())
265+
}
266+
267+
#[test]
268+
fn test_last_value_return_type() -> Result<()> {
269+
let fun = WindowFunction::from_str("last_value")?;
270+
let observed = return_type(&fun, &[DataType::Utf8])?;
271+
assert_eq!(DataType::Utf8, observed);
272+
273+
Ok(())
274+
}
275+
276+
#[test]
277+
fn test_lead_return_type() -> Result<()> {
278+
let fun = WindowFunction::from_str("lead")?;
279+
let observed = return_type(&fun, &[DataType::Utf8])?;
280+
assert_eq!(DataType::Utf8, observed);
281+
282+
Ok(())
283+
}
284+
285+
#[test]
286+
fn test_lag_return_type() -> Result<()> {
287+
let fun = WindowFunction::from_str("lag")?;
288+
let observed = return_type(&fun, &[DataType::Utf8])?;
289+
assert_eq!(DataType::Utf8, observed);
290+
291+
Ok(())
292+
}
293+
294+
#[test]
295+
fn test_cume_dist_return_type() -> Result<()> {
296+
let fun = WindowFunction::from_str("cume_dist")?;
297+
let observed = return_type(&fun, &[DataType::Float64])?;
298+
assert_eq!(DataType::Float64, observed);
299+
201300
Ok(())
202301
}
203302
}

0 commit comments

Comments
 (0)