Skip to content

Commit

Permalink
fix: Panic in UNION ALL queries (#4796)
Browse files Browse the repository at this point in the history
* fix/union_all_panic:
 Improve MetricCollector by incrementing level and fix underflow issue; add tests for UNION ALL queries

* chore: remove useless documentation

* fix/union_all_panic: Add order by clause to UNION ALL select queries in tests
  • Loading branch information
v0y4g3r authored Oct 11, 2024
1 parent d168bde commit 7dd0e3a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/common/recordbatch/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ impl ExecutionPlanVisitor for MetricCollector {
level: self.current_level,
metrics: vec![],
});
self.current_level += 1;
return Ok(true);
};

Expand Down Expand Up @@ -365,8 +366,7 @@ impl ExecutionPlanVisitor for MetricCollector {
}

fn post_visit(&mut self, _plan: &dyn ExecutionPlan) -> std::result::Result<bool, Self::Error> {
// the last minus will underflow
self.current_level = self.current_level.wrapping_sub(1);
self.current_level -= 1;
Ok(true)
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/standalone/common/select/union_all.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT 123 as a, 'h' as b UNION ALL SELECT 456 as a, 'e' as b UNION ALL SELECT 789 as a, 'l' as b order by a;

+-----+---+
| a | b |
+-----+---+
| 123 | h |
| 456 | e |
| 789 | l |
+-----+---+

1 change: 1 addition & 0 deletions tests/cases/standalone/common/select/union_all.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT 123 as a, 'h' as b UNION ALL SELECT 456 as a, 'e' as b UNION ALL SELECT 789 as a, 'l' as b order by a;

0 comments on commit 7dd0e3a

Please sign in to comment.