Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
jimexist committed Feb 6, 2022
1 parent b53e5a1 commit 8170b2e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 66 deletions.
71 changes: 71 additions & 0 deletions datafusion-expr/src/window_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,74 @@ impl FromStr for BuiltInWindowFunction {
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_window_function_case_insensitive() -> Result<()> {
let names = vec![
"row_number",
"rank",
"dense_rank",
"percent_rank",
"cume_dist",
"ntile",
"lag",
"lead",
"first_value",
"last_value",
"nth_value",
"min",
"max",
"count",
"avg",
"sum",
];
for name in names {
let fun = WindowFunction::from_str(name)?;
let fun2 = WindowFunction::from_str(name.to_uppercase().as_str())?;
assert_eq!(fun, fun2);
assert_eq!(fun.to_string(), name.to_uppercase());
}
Ok(())
}

#[test]
fn test_window_function_from_str() -> Result<()> {
assert_eq!(
WindowFunction::from_str("max")?,
WindowFunction::AggregateFunction(AggregateFunction::Max)
);
assert_eq!(
WindowFunction::from_str("min")?,
WindowFunction::AggregateFunction(AggregateFunction::Min)
);
assert_eq!(
WindowFunction::from_str("avg")?,
WindowFunction::AggregateFunction(AggregateFunction::Avg)
);
assert_eq!(
WindowFunction::from_str("cume_dist")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::CumeDist)
);
assert_eq!(
WindowFunction::from_str("first_value")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::FirstValue)
);
assert_eq!(
WindowFunction::from_str("LAST_value")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::LastValue)
);
assert_eq!(
WindowFunction::from_str("LAG")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::Lag)
);
assert_eq!(
WindowFunction::from_str("LEAD")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::Lead)
);
Ok(())
}
}
67 changes: 1 addition & 66 deletions datafusion/src/physical_plan/window_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,72 +190,7 @@ pub(crate) trait BuiltInWindowFunctionExpr: Send + Sync + std::fmt::Debug {
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_window_function_case_insensitive() -> Result<()> {
let names = vec![
"row_number",
"rank",
"dense_rank",
"percent_rank",
"cume_dist",
"ntile",
"lag",
"lead",
"first_value",
"last_value",
"nth_value",
"min",
"max",
"count",
"avg",
"sum",
];
for name in names {
let fun = WindowFunction::from_str(name)?;
let fun2 = WindowFunction::from_str(name.to_uppercase().as_str())?;
assert_eq!(fun, fun2);
assert_eq!(fun.to_string(), name.to_uppercase());
}
Ok(())
}

#[test]
fn test_window_function_from_str() -> Result<()> {
assert_eq!(
WindowFunction::from_str("max")?,
WindowFunction::AggregateFunction(AggregateFunction::Max)
);
assert_eq!(
WindowFunction::from_str("min")?,
WindowFunction::AggregateFunction(AggregateFunction::Min)
);
assert_eq!(
WindowFunction::from_str("avg")?,
WindowFunction::AggregateFunction(AggregateFunction::Avg)
);
assert_eq!(
WindowFunction::from_str("cume_dist")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::CumeDist)
);
assert_eq!(
WindowFunction::from_str("first_value")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::FirstValue)
);
assert_eq!(
WindowFunction::from_str("LAST_value")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::LastValue)
);
assert_eq!(
WindowFunction::from_str("LAG")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::Lag)
);
assert_eq!(
WindowFunction::from_str("LEAD")?,
WindowFunction::BuiltInWindowFunction(BuiltInWindowFunction::Lead)
);
Ok(())
}
use std::str::FromStr;

#[test]
fn test_count_return_type() -> Result<()> {
Expand Down

0 comments on commit 8170b2e

Please sign in to comment.