Skip to content

Commit d460abb

Browse files
Migrate physical plan tests to insta (Part-1) (#15313)
* Basic setup done for physical plan insta tests * Migrated tests to insta in aggregate/mod.rs * Migrated tests to insta in aggregate/topk/priority_map.rs * Migrated tests to insta in joins * Fallback to previous implementation in a test due to an issue (#15312) * Fix formatting * Update Cargo.toml * Revert any Cargo.lock changes * Clean workspace and attempt fixing failing build test * format Cargo.toml * Add insta as a dev-dependency instead * Update datafusion/physical-plan/src/aggregates/mod.rs Co-authored-by: Dmitrii Blaginin <[email protected]> * Preserved comments from aggregates/mod.rs * Resolved errors regarding dependencies and formatting --------- Co-authored-by: Dmitrii Blaginin <[email protected]>
1 parent 5ab23b5 commit d460abb

File tree

7 files changed

+730
-678
lines changed

7 files changed

+730
-678
lines changed

Diff for: Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: datafusion/physical-plan/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ tokio = { workspace = true }
6868
criterion = { workspace = true, features = ["async_futures"] }
6969
datafusion-functions-aggregate = { workspace = true }
7070
datafusion-functions-window = { workspace = true }
71+
insta = { workspace = true }
7172
rand = { workspace = true }
7273
rstest = { workspace = true }
7374
rstest_reuse = "0.7.0"

Diff for: datafusion/physical-plan/src/aggregates/mod.rs

+200-182
Large diffs are not rendered by default.

Diff for: datafusion/physical-plan/src/aggregates/topk/priority_map.rs

+23-30
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ mod tests {
113113
};
114114
use arrow::datatypes::{Field, Schema, SchemaRef};
115115
use arrow::util::pretty::pretty_format_batches;
116+
use insta::assert_snapshot;
116117
use std::sync::Arc;
117118

118119
#[test]
@@ -180,15 +181,15 @@ mod tests {
180181
let cols = agg.emit()?;
181182
let batch = RecordBatch::try_new(test_schema(), cols)?;
182183
let actual = format!("{}", pretty_format_batches(&[batch])?);
183-
let expected = r#"
184+
185+
assert_snapshot!(actual, @r#"
184186
+----------+--------------+
185187
| trace_id | timestamp_ms |
186188
+----------+--------------+
187189
| 1 | 1 |
188190
+----------+--------------+
189191
"#
190-
.trim();
191-
assert_eq!(actual, expected);
192+
);
192193

193194
Ok(())
194195
}
@@ -205,15 +206,15 @@ mod tests {
205206
let cols = agg.emit()?;
206207
let batch = RecordBatch::try_new(test_schema(), cols)?;
207208
let actual = format!("{}", pretty_format_batches(&[batch])?);
208-
let expected = r#"
209+
210+
assert_snapshot!(actual, @r#"
209211
+----------+--------------+
210212
| trace_id | timestamp_ms |
211213
+----------+--------------+
212214
| 1 | 1 |
213215
+----------+--------------+
214216
"#
215-
.trim();
216-
assert_eq!(actual, expected);
217+
);
217218

218219
Ok(())
219220
}
@@ -230,15 +231,14 @@ mod tests {
230231
let cols = agg.emit()?;
231232
let batch = RecordBatch::try_new(test_schema(), cols)?;
232233
let actual = format!("{}", pretty_format_batches(&[batch])?);
233-
let expected = r#"
234+
assert_snapshot!(actual, @r#"
234235
+----------+--------------+
235236
| trace_id | timestamp_ms |
236237
+----------+--------------+
237238
| 2 | 2 |
238239
+----------+--------------+
239240
"#
240-
.trim();
241-
assert_eq!(actual, expected);
241+
);
242242

243243
Ok(())
244244
}
@@ -255,15 +255,14 @@ mod tests {
255255
let cols = agg.emit()?;
256256
let batch = RecordBatch::try_new(test_schema(), cols)?;
257257
let actual = format!("{}", pretty_format_batches(&[batch])?);
258-
let expected = r#"
258+
assert_snapshot!(actual, @r#"
259259
+----------+--------------+
260260
| trace_id | timestamp_ms |
261261
+----------+--------------+
262262
| 1 | 1 |
263263
+----------+--------------+
264264
"#
265-
.trim();
266-
assert_eq!(actual, expected);
265+
);
267266

268267
Ok(())
269268
}
@@ -280,15 +279,14 @@ mod tests {
280279
let cols = agg.emit()?;
281280
let batch = RecordBatch::try_new(test_schema(), cols)?;
282281
let actual = format!("{}", pretty_format_batches(&[batch])?);
283-
let expected = r#"
282+
assert_snapshot!(actual, @r#"
284283
+----------+--------------+
285284
| trace_id | timestamp_ms |
286285
+----------+--------------+
287286
| 1 | 2 |
288287
+----------+--------------+
289288
"#
290-
.trim();
291-
assert_eq!(actual, expected);
289+
);
292290

293291
Ok(())
294292
}
@@ -305,15 +303,14 @@ mod tests {
305303
let cols = agg.emit()?;
306304
let batch = RecordBatch::try_new(test_schema(), cols)?;
307305
let actual = format!("{}", pretty_format_batches(&[batch])?);
308-
let expected = r#"
306+
assert_snapshot!(actual, @r#"
309307
+----------+--------------+
310308
| trace_id | timestamp_ms |
311309
+----------+--------------+
312310
| 1 | 1 |
313311
+----------+--------------+
314312
"#
315-
.trim();
316-
assert_eq!(actual, expected);
313+
);
317314

318315
Ok(())
319316
}
@@ -330,15 +327,14 @@ mod tests {
330327
let cols = agg.emit()?;
331328
let batch = RecordBatch::try_new(test_schema(), cols)?;
332329
let actual = format!("{}", pretty_format_batches(&[batch])?);
333-
let expected = r#"
330+
assert_snapshot!(actual, @r#"
334331
+----------+--------------+
335332
| trace_id | timestamp_ms |
336333
+----------+--------------+
337334
| 2 | 2 |
338335
+----------+--------------+
339336
"#
340-
.trim();
341-
assert_eq!(actual, expected);
337+
);
342338

343339
Ok(())
344340
}
@@ -355,15 +351,14 @@ mod tests {
355351
let cols = agg.emit()?;
356352
let batch = RecordBatch::try_new(test_schema(), cols)?;
357353
let actual = format!("{}", pretty_format_batches(&[batch])?);
358-
let expected = r#"
354+
assert_snapshot!(actual, @r#"
359355
+----------+--------------+
360356
| trace_id | timestamp_ms |
361357
+----------+--------------+
362358
| 1 | 1 |
363359
+----------+--------------+
364360
"#
365-
.trim();
366-
assert_eq!(actual, expected);
361+
);
367362

368363
Ok(())
369364
}
@@ -380,15 +375,14 @@ mod tests {
380375
let cols = agg.emit()?;
381376
let batch = RecordBatch::try_new(test_schema(), cols)?;
382377
let actual = format!("{}", pretty_format_batches(&[batch])?);
383-
let expected = r#"
378+
assert_snapshot!(actual, @r#"
384379
+----------+--------------+
385380
| trace_id | timestamp_ms |
386381
+----------+--------------+
387382
| 1 | 2 |
388383
+----------+--------------+
389384
"#
390-
.trim();
391-
assert_eq!(actual, expected);
385+
);
392386

393387
Ok(())
394388
}
@@ -406,16 +400,15 @@ mod tests {
406400
let cols = agg.emit()?;
407401
let batch = RecordBatch::try_new(test_schema(), cols)?;
408402
let actual = format!("{}", pretty_format_batches(&[batch])?);
409-
let expected = r#"
403+
assert_snapshot!(actual, @r#"
410404
+----------+--------------+
411405
| trace_id | timestamp_ms |
412406
+----------+--------------+
413407
| | 3 |
414408
| 1 | 1 |
415409
+----------+--------------+
416410
"#
417-
.trim();
418-
assert_eq!(actual, expected);
411+
);
419412

420413
Ok(())
421414
}

Diff for: datafusion/physical-plan/src/joins/cross_join.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,9 @@ mod tests {
645645
use crate::common;
646646
use crate::test::build_table_scan_i32;
647647

648-
use datafusion_common::{assert_batches_sorted_eq, assert_contains};
648+
use datafusion_common::{assert_contains, test_util::batches_to_sort_string};
649649
use datafusion_execution::runtime_env::RuntimeEnvBuilder;
650+
use insta::assert_snapshot;
650651

651652
async fn join_collect(
652653
left: Arc<dyn ExecutionPlan>,
@@ -829,20 +830,19 @@ mod tests {
829830
let (columns, batches) = join_collect(left, right, task_ctx).await?;
830831

831832
assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "b2", "c2"]);
832-
let expected = [
833-
"+----+----+----+----+----+----+",
834-
"| a1 | b1 | c1 | a2 | b2 | c2 |",
835-
"+----+----+----+----+----+----+",
836-
"| 1 | 4 | 7 | 10 | 12 | 14 |",
837-
"| 1 | 4 | 7 | 11 | 13 | 15 |",
838-
"| 2 | 5 | 8 | 10 | 12 | 14 |",
839-
"| 2 | 5 | 8 | 11 | 13 | 15 |",
840-
"| 3 | 6 | 9 | 10 | 12 | 14 |",
841-
"| 3 | 6 | 9 | 11 | 13 | 15 |",
842-
"+----+----+----+----+----+----+",
843-
];
844-
845-
assert_batches_sorted_eq!(expected, &batches);
833+
834+
assert_snapshot!(batches_to_sort_string(&batches), @r#"
835+
+----+----+----+----+----+----+
836+
| a1 | b1 | c1 | a2 | b2 | c2 |
837+
+----+----+----+----+----+----+
838+
| 1 | 4 | 7 | 10 | 12 | 14 |
839+
| 1 | 4 | 7 | 11 | 13 | 15 |
840+
| 2 | 5 | 8 | 10 | 12 | 14 |
841+
| 2 | 5 | 8 | 11 | 13 | 15 |
842+
| 3 | 6 | 9 | 10 | 12 | 14 |
843+
| 3 | 6 | 9 | 11 | 13 | 15 |
844+
+----+----+----+----+----+----+
845+
"#);
846846

847847
Ok(())
848848
}

0 commit comments

Comments
 (0)