@@ -25,8 +25,8 @@ use crate::physical_optimizer::test_utils::{
2525 schema,
2626} ;
2727
28+ use arrow:: compute:: SortOptions ;
2829use arrow:: datatypes:: DataType ;
29- use arrow:: { compute:: SortOptions , util:: pretty:: pretty_format_batches} ;
3030use datafusion:: prelude:: SessionContext ;
3131use datafusion_common:: Result ;
3232use datafusion_execution:: config:: SessionConfig ;
@@ -40,12 +40,12 @@ use datafusion_physical_plan::{
4040 limit:: { GlobalLimitExec , LocalLimitExec } ,
4141} ;
4242
43- async fn run_plan_and_format ( plan : Arc < dyn ExecutionPlan > ) -> Result < String > {
43+ async fn run_plan_and_count_rows ( plan : Arc < dyn ExecutionPlan > ) -> Result < usize > {
4444 let cfg = SessionConfig :: new ( ) . with_target_partitions ( 1 ) ;
4545 let ctx = SessionContext :: new_with_config ( cfg) ;
4646 let batches = collect ( plan, ctx. task_ctx ( ) ) . await ?;
47- let actual = format ! ( "{}" , pretty_format_batches ( & batches ) ? ) ;
48- Ok ( actual )
47+ // These plans have LIMIT without ORDER BY, so the row order is not stable.
48+ Ok ( batches . iter ( ) . map ( |batch| batch . num_rows ( ) ) . sum ( ) )
4949}
5050
5151#[ tokio:: test]
@@ -86,20 +86,7 @@ async fn test_partial_final() -> Result<()> {
8686 DataSourceExec: partitions=1, partition_sizes=[1]
8787 "
8888 ) ;
89- let expected = run_plan_and_format ( plan) . await ?;
90- assert_snapshot ! (
91- expected,
92- @r"
93- +---+
94- | a |
95- +---+
96- | 1 |
97- | 2 |
98- | |
99- | 4 |
100- +---+
101- "
102- ) ;
89+ assert_eq ! ( run_plan_and_count_rows( plan) . await ?, 4 ) ;
10390
10491 Ok ( ( ) )
10592}
@@ -134,20 +121,7 @@ async fn test_single_local() -> Result<()> {
134121 DataSourceExec: partitions=1, partition_sizes=[1]
135122 "
136123 ) ;
137- let expected = run_plan_and_format ( plan) . await ?;
138- assert_snapshot ! (
139- expected,
140- @r"
141- +---+
142- | a |
143- +---+
144- | 1 |
145- | 2 |
146- | |
147- | 4 |
148- +---+
149- "
150- ) ;
124+ assert_eq ! ( run_plan_and_count_rows( plan) . await ?, 4 ) ;
151125 Ok ( ( ) )
152126}
153127
@@ -182,19 +156,7 @@ async fn test_single_global() -> Result<()> {
182156 DataSourceExec: partitions=1, partition_sizes=[1]
183157 "
184158 ) ;
185- let expected = run_plan_and_format ( plan) . await ?;
186- assert_snapshot ! (
187- expected,
188- @r"
189- +---+
190- | a |
191- +---+
192- | 2 |
193- | |
194- | 4 |
195- +---+
196- "
197- ) ;
159+ assert_eq ! ( run_plan_and_count_rows( plan) . await ?, 3 ) ;
198160 Ok ( ( ) )
199161}
200162
@@ -237,20 +199,7 @@ async fn test_distinct_cols_different_than_group_by_cols() -> Result<()> {
237199 DataSourceExec: partitions=1, partition_sizes=[1]
238200 "
239201 ) ;
240- let expected = run_plan_and_format ( plan) . await ?;
241- assert_snapshot ! (
242- expected,
243- @r"
244- +---+
245- | a |
246- +---+
247- | 1 |
248- | 2 |
249- | |
250- | 4 |
251- +---+
252- "
253- ) ;
202+ assert_eq ! ( run_plan_and_count_rows( plan) . await ?, 4 ) ;
254203 Ok ( ( ) )
255204}
256205
0 commit comments