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 Jun 22, 2021
1 parent 8095487 commit 2f83560
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 62 deletions.
11 changes: 9 additions & 2 deletions datafusion/src/logical_plan/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,11 +1298,18 @@ impl fmt::Debug for Expr {
}
Expr::WindowFunction {
fun,
ref args,
args,
partition_by,
order_by,
window_frame,
..
} => {
fmt_function(f, &fun.to_string(), false, args)?;
if !partition_by.is_empty() {
write!(f, " PARTITION BY {:?}", partition_by)?;
}
if !order_by.is_empty() {
write!(f, " ORDER BY {:?}", order_by)?;
}
if let Some(window_frame) = window_frame {
write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion datafusion/src/physical_plan/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl DefaultPhysicalPlanner {
.map(|e| {
self.create_window_expr(
e,
&logical_input_schema,
logical_input_schema,
&physical_input_schema,
ctx_state,
)
Expand Down
95 changes: 36 additions & 59 deletions datafusion/src/sql/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2839,9 +2839,8 @@ mod tests {
let sql = "SELECT order_id, MAX(qty) OVER (PARTITION BY order_id) from orders";
let expected = "\
Projection: #order_id, #MAX(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) PARTITION BY [#order_id]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -2862,11 +2861,9 @@ mod tests {
let sql = "SELECT order_id, MAX(qty) OVER (ORDER BY order_id), MIN(qty) OVER (ORDER BY order_id DESC) from orders";
let expected = "\
Projection: #order_id, #MAX(qty), #MIN(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #order_id DESC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) ORDER BY [#order_id ASC NULLS FIRST]]]\
\n WindowAggr: windowExpr=[[MIN(#qty) ORDER BY [#order_id DESC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -2875,11 +2872,9 @@ mod tests {
let sql = "SELECT order_id, MAX(qty) OVER (ORDER BY order_id ROWS BETWEEN 3 PRECEDING and 3 FOLLOWING), MIN(qty) OVER (ORDER BY order_id DESC) from orders";
let expected = "\
Projection: #order_id, #MAX(qty) ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING, #MIN(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty) ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING]]\
\n Sort: #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #order_id DESC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) ORDER BY [#order_id ASC NULLS FIRST] ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING]]\
\n WindowAggr: windowExpr=[[MIN(#qty) ORDER BY [#order_id DESC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -2888,11 +2883,9 @@ mod tests {
let sql = "SELECT order_id, MAX(qty) OVER (ORDER BY order_id ROWS 3 PRECEDING), MIN(qty) OVER (ORDER BY order_id DESC) from orders";
let expected = "\
Projection: #order_id, #MAX(qty) ROWS BETWEEN 3 PRECEDING AND CURRENT ROW, #MIN(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty) ROWS BETWEEN 3 PRECEDING AND CURRENT ROW]]\
\n Sort: #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #order_id DESC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) ORDER BY [#order_id ASC NULLS FIRST] ROWS BETWEEN 3 PRECEDING AND CURRENT ROW]]\
\n WindowAggr: windowExpr=[[MIN(#qty) ORDER BY [#order_id DESC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand Down Expand Up @@ -2933,11 +2926,9 @@ 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) GROUPS BETWEEN 3 PRECEDING AND CURRENT ROW]]\
\n Sort: #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #order_id DESC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) ORDER BY [#order_id ASC NULLS FIRST] GROUPS BETWEEN 3 PRECEDING AND CURRENT ROW]]\
\n WindowAggr: windowExpr=[[MIN(#qty) ORDER BY [#order_id DESC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -2958,11 +2949,9 @@ mod tests {
let sql = "SELECT order_id, MAX(qty) OVER (ORDER BY order_id), MIN(qty) OVER (ORDER BY (order_id + 1)) from orders";
let expected = "\
Projection: #order_id, #MAX(qty), #MIN(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #order_id Plus Int64(1) ASC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) ORDER BY [#order_id ASC NULLS FIRST]]]\
\n WindowAggr: windowExpr=[[MIN(#qty) ORDER BY [#order_id Plus Int64(1) ASC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -2985,11 +2974,9 @@ mod tests {
let expected = "\
Projection: #order_id, #MAX(qty), #SUM(qty), #MIN(qty)\
\n WindowAggr: windowExpr=[[SUM(#qty)]]\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #qty ASC NULLS FIRST, #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST, #qty ASC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) ORDER BY [#qty ASC NULLS FIRST, #order_id ASC NULLS FIRST]]]\
\n WindowAggr: windowExpr=[[MIN(#qty) ORDER BY [#order_id ASC NULLS FIRST, #qty ASC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -3012,11 +2999,9 @@ mod tests {
let expected = "\
Projection: #order_id, #MAX(qty), #SUM(qty), #MIN(qty)\
\n WindowAggr: windowExpr=[[SUM(#qty)]]\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST, #qty ASC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) ORDER BY [#order_id ASC NULLS FIRST]]]\
\n WindowAggr: windowExpr=[[MIN(#qty) ORDER BY [#order_id ASC NULLS FIRST, #qty ASC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -3043,11 +3028,9 @@ mod tests {
Sort: #order_id ASC NULLS FIRST\
\n Projection: #order_id, #MAX(qty), #SUM(qty), #MIN(qty)\
\n WindowAggr: windowExpr=[[SUM(#qty)]]\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #qty ASC NULLS FIRST, #order_id ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST, #qty ASC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) ORDER BY [#qty ASC NULLS FIRST, #order_id ASC NULLS FIRST]]]\
\n WindowAggr: windowExpr=[[MIN(#qty) ORDER BY [#order_id ASC NULLS FIRST, #qty ASC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -3066,9 +3049,8 @@ mod tests {
"SELECT order_id, MAX(qty) OVER (PARTITION BY order_id ORDER BY qty) from orders";
let expected = "\
Projection: #order_id, #MAX(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST, #qty ASC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) PARTITION BY [#order_id] ORDER BY [#qty ASC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -3087,9 +3069,8 @@ mod tests {
"SELECT order_id, MAX(qty) OVER (PARTITION BY order_id, qty ORDER BY qty) from orders";
let expected = "\
Projection: #order_id, #MAX(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST, #qty ASC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) PARTITION BY [#order_id, #qty] ORDER BY [#qty ASC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -3111,11 +3092,9 @@ mod tests {
"SELECT order_id, MAX(qty) OVER (PARTITION BY order_id, qty ORDER BY qty), MIN(qty) OVER (PARTITION BY qty ORDER BY order_id) from orders";
let expected = "\
Projection: #order_id, #MAX(qty), #MIN(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST, #qty ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #qty ASC NULLS FIRST, #order_id ASC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) PARTITION BY [#order_id, #qty] ORDER BY [#qty ASC NULLS FIRST]]]\
\n WindowAggr: windowExpr=[[MIN(#qty) PARTITION BY [#qty] ORDER BY [#order_id ASC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand All @@ -3136,11 +3115,9 @@ mod tests {
"SELECT order_id, MAX(qty) OVER (PARTITION BY order_id ORDER BY qty), MIN(qty) OVER (PARTITION BY order_id, qty ORDER BY price) from orders";
let expected = "\
Projection: #order_id, #MAX(qty), #MIN(qty)\
\n WindowAggr: windowExpr=[[MAX(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST, #qty ASC NULLS FIRST\
\n WindowAggr: windowExpr=[[MIN(#qty)]]\
\n Sort: #order_id ASC NULLS FIRST, #qty ASC NULLS FIRST, #price ASC NULLS FIRST\
\n TableScan: orders projection=None";
\n WindowAggr: windowExpr=[[MAX(#qty) PARTITION BY [#order_id] ORDER BY [#qty ASC NULLS FIRST]]]\
\n WindowAggr: windowExpr=[[MIN(#qty) PARTITION BY [#order_id, #qty] ORDER BY [#price ASC NULLS FIRST]]]\
\n TableScan: orders projection=None";
quick_test(sql, expected);
}

Expand Down

0 comments on commit 2f83560

Please sign in to comment.