Skip to content

Commit 1616314

Browse files
committed
add more test cases
1 parent ff837eb commit 1616314

1 file changed

Lines changed: 77 additions & 2 deletions

File tree

‎datafusion/optimizer/src/eliminate_limit.rs‎

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ impl OptimizerRule for EliminateLimit {
142142
mod tests {
143143
use super::*;
144144
use crate::test::*;
145-
use datafusion_expr::{col, logical_plan::builder::LogicalPlanBuilder, sum};
145+
use datafusion_common::Column;
146+
use datafusion_expr::{
147+
col,
148+
logical_plan::{builder::LogicalPlanBuilder, JoinType},
149+
sum,
150+
};
146151

147152
fn assert_optimized_plan_eq(plan: &LogicalPlan, expected: &str) {
148153
let rule = EliminateLimit::new();
@@ -197,7 +202,7 @@ mod tests {
197202
}
198203

199204
#[test]
200-
fn multi_limit_offset_eliminate() {
205+
fn limit_fetch_with_ancestor_limit_skip() {
201206
let table_scan = test_table_scan().unwrap();
202207
let plan = LogicalPlanBuilder::from(table_scan)
203208
.aggregate(vec![col("a")], vec![sum(col("b"))])
@@ -235,4 +240,74 @@ mod tests {
235240
\n EmptyRelation";
236241
assert_optimized_plan_eq(&plan, expected);
237242
}
243+
244+
#[test]
245+
fn limit_fetch_with_ancestor_limit_fetch() {
246+
let table_scan = test_table_scan().unwrap();
247+
let plan = LogicalPlanBuilder::from(table_scan)
248+
.aggregate(vec![col("a")], vec![sum(col("b"))])
249+
.unwrap()
250+
.limit(None, Some(2))
251+
.unwrap()
252+
.sort(vec![col("a")])
253+
.unwrap()
254+
.limit(None, Some(1))
255+
.unwrap()
256+
.build()
257+
.unwrap();
258+
259+
let expected = "Limit: skip=None, fetch=1\
260+
\n Sort: #test.a\
261+
\n Limit: skip=None, fetch=2\
262+
\n Aggregate: groupBy=[[#test.a]], aggr=[[SUM(#test.b)]]\
263+
\n TableScan: test";
264+
assert_optimized_plan_eq(&plan, expected);
265+
}
266+
267+
#[test]
268+
fn limit_with_ancestor_limit() {
269+
let table_scan = test_table_scan().unwrap();
270+
let plan = LogicalPlanBuilder::from(table_scan)
271+
.aggregate(vec![col("a")], vec![sum(col("b"))])
272+
.unwrap()
273+
.limit(Some(2), Some(1))
274+
.unwrap()
275+
.sort(vec![col("a")])
276+
.unwrap()
277+
.limit(Some(3), Some(1))
278+
.unwrap()
279+
.build()
280+
.unwrap();
281+
282+
let expected = "Limit: skip=3, fetch=1\
283+
\n Sort: #test.a\
284+
\n EmptyRelation";
285+
assert_optimized_plan_eq(&plan, expected);
286+
}
287+
288+
#[test]
289+
fn limit_join_with_ancestor_limit() {
290+
let table_scan = test_table_scan().unwrap();
291+
let table_scan_inner = test_table_scan_with_name("test1").unwrap();
292+
let plan = LogicalPlanBuilder::from(table_scan)
293+
.limit(Some(2), Some(1))
294+
.unwrap()
295+
.join_using(
296+
&table_scan_inner,
297+
JoinType::Inner,
298+
vec![Column::from_name("a".to_string())],
299+
)
300+
.unwrap()
301+
.limit(Some(3), Some(1))
302+
.unwrap()
303+
.build()
304+
.unwrap();
305+
306+
let expected = "Limit: skip=3, fetch=1\
307+
\n Inner Join: Using #test.a = #test1.a\
308+
\n Limit: skip=2, fetch=1\
309+
\n TableScan: test\
310+
\n TableScan: test1";
311+
assert_optimized_plan_eq(&plan, expected);
312+
}
238313
}

0 commit comments

Comments
 (0)