Skip to content

Commit

Permalink
adding more formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiayu Liu committed Jun 5, 2021
1 parent f2afee2 commit 0e2c3d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
19 changes: 17 additions & 2 deletions datafusion/src/logical_plan/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,23 @@ impl fmt::Debug for Expr {
Expr::ScalarUDF { fun, ref args, .. } => {
fmt_function(f, &fun.name, false, args)
}
Expr::WindowFunction { fun, ref args, .. } => {
fmt_function(f, &fun.to_string(), false, args)
Expr::WindowFunction {
fun,
ref args,
window_frame,
..
} => {
fmt_function(f, &fun.to_string(), false, args)?;
if let Some(window_frame) = window_frame {
write!(
f,
" {} BETWEEN {} AND {}",
window_frame.units,
window_frame.start_bound,
window_frame.end_bound
)?;
}
Ok(())
}
Expr::AggregateFunction {
fun,
Expand Down
6 changes: 3 additions & 3 deletions datafusion/src/sql/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2818,7 +2818,7 @@ mod tests {
let sql = "SELECT order_id, MAX(qty) OVER (ORDER BY order_id RANGE BETWEEN 3 PRECEDING and 3 FOLLOWING), MIN(qty) OVER (ORDER BY order_id DESC) from orders";
let expected = "\
Projection: #order_id, #MAX(qty) RANGE BETWEEN 3 PRECEDING AND 3 FOLLOWING, #MIN(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]] partitionBy=[]\
\n WindowAggr: windowExpr=[[MAX(#qty) RANGE BETWEEN 3 PRECEDING AND 3 FOLLOWING]] partitionBy=[]\
\n Sort: #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]] partitionBy=[]\
\n Sort: #order_id DESC NULLS FIRST\
Expand All @@ -2831,7 +2831,7 @@ mod tests {
let sql = "SELECT order_id, MAX(qty) OVER (ORDER BY order_id RANGE 3 PRECEDING), MIN(qty) OVER (ORDER BY order_id DESC) from orders";
let expected = "\
Projection: #order_id, #MAX(qty) RANGE BETWEEN 3 PRECEDING AND CURRENT ROW, #MIN(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]] partitionBy=[]\
\n WindowAggr: windowExpr=[[MAX(#qty) RANGE BETWEEN 3 PRECEDING AND CURRENT ROW]] partitionBy=[]\
\n Sort: #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]] partitionBy=[]\
\n Sort: #order_id DESC NULLS FIRST\
Expand All @@ -2844,7 +2844,7 @@ mod tests {
let sql = "SELECT order_id, MAX(qty) OVER (ORDER BY order_id GROUPS 3 PRECEDING), MIN(qty) OVER (ORDER BY order_id DESC) from orders";
let expected = "\
Projection: #order_id, #MAX(qty) GROUPS BETWEEN 3 PRECEDING AND CURRENT ROW, #MIN(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]] partitionBy=[]\
\n WindowAggr: windowExpr=[[MAX(#qty) GROUPS BETWEEN 3 PRECEDING AND CURRENT ROW]] partitionBy=[]\
\n Sort: #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]] partitionBy=[]\
\n Sort: #order_id DESC NULLS FIRST\
Expand Down

0 comments on commit 0e2c3d0

Please sign in to comment.