jackwener commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1034276095
##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -606,6 +622,106 @@ mod test {
assert_optimized_plan_eq(&outer_query, expected)
}
+ #[test]
+ fn limit_should_push_down_join_without_condition() -> Result<()> {
+ let table_scan_1 = test_table_scan()?;
+ let table_scan_2 = test_table_scan_with_name("test2")?;
+ let left_keys: Vec<&str> = Vec::new();
+ let right_keys: Vec<&str> = Vec::new();
+ let plan = LogicalPlanBuilder::from(table_scan_1.clone())
+ .join(
+ &LogicalPlanBuilder::from(table_scan_2.clone()).build()?,
+ JoinType::Left,
+ (left_keys.clone(), right_keys.clone()),
+ None,
+ )?
+ .limit(0, Some(1000))?
+ .build()?;
+
+ let expected = "Limit: skip=0, fetch=1000\
+ \n Left Join: \
+ \n Limit: skip=0, fetch=1000\
+ \n TableScan: test, fetch=1000\
+ \n Limit: skip=0, fetch=1000\
+ \n TableScan: test2, fetch=1000";
+
+ assert_optimized_plan_eq(&plan, expected).unwrap();
+
+ let plan = LogicalPlanBuilder::from(table_scan_1.clone())
+ .join(
+ &LogicalPlanBuilder::from(table_scan_2.clone()).build()?,
+ JoinType::Right,
+ (left_keys.clone(), right_keys.clone()),
+ None,
+ )?
+ .limit(0, Some(1000))?
+ .build()?;
+
+ let expected = "Limit: skip=0, fetch=1000\
+ \n Right Join: \
+ \n Limit: skip=0, fetch=1000\
+ \n TableScan: test, fetch=1000\
+ \n Limit: skip=0, fetch=1000\
+ \n TableScan: test2, fetch=1000";
+
+ assert_optimized_plan_eq(&plan, expected).unwrap();
Review Comment:
```suggestion
assert_optimized_plan_eq(&plan, expected)?;
```
##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,18 @@ impl OptimizerRule for LimitPushDown {
LogicalPlan::Join(join) => {
let limit = fetch + skip;
let new_join = match join.join_type {
+ JoinType::Left | JoinType::Right | JoinType::Full
+ if is_no_join_condition(join) =>
+ {
+ // push left and right
+ push_down_join(join, Some(limit), Some(limit))
+ }
+ JoinType::LeftSemi | JoinType::LeftAnti
+ if is_no_join_condition(join) =>
+ {
+ // push left
+ push_down_join(join, Some(limit), None)
+ }
JoinType::Left => push_down_join(join, Some(limit), None),
JoinType::Right => push_down_join(join, None, Some(limit)),
Review Comment:
remove these
##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,18 @@ impl OptimizerRule for LimitPushDown {
LogicalPlan::Join(join) => {
let limit = fetch + skip;
let new_join = match join.join_type {
+ JoinType::Left | JoinType::Right | JoinType::Full
+ if is_no_join_condition(join) =>
+ {
+ // push left and right
+ push_down_join(join, Some(limit), Some(limit))
+ }
+ JoinType::LeftSemi | JoinType::LeftAnti
Review Comment:
Forget `RightSemi/RightAnti`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]