Skip to content

Commit 401f2e2

Browse files
committed
refactor: update tests
1 parent 66aa31a commit 401f2e2

File tree

3 files changed

+24
-48
lines changed

3 files changed

+24
-48
lines changed

datafusion/optimizer/src/eliminate_one_union.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ mod tests {
8888
}
8989

9090
fn assert_optimized_plan_equal(plan: LogicalPlan, expected: &str) -> Result<()> {
91-
assert_optimized_plan_eq_with_rules(
91+
assert_optimized_plan_with_rules(
9292
vec![Arc::new(EliminateOneUnion::new())],
9393
plan,
9494
expected,
95+
true,
9596
)
9697
}
9798

datafusion/optimizer/src/propagate_empty_relation.rs

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,8 @@ mod tests {
255255
use crate::eliminate_filter::EliminateFilter;
256256
use crate::eliminate_nested_union::EliminateNestedUnion;
257257
use crate::test::{
258-
assert_optimized_plan_eq, assert_optimized_plan_eq_with_rules,
259-
assert_optimized_plan_ne_with_rules, test_table_scan, test_table_scan_fields,
260-
test_table_scan_with_name,
258+
assert_optimized_plan_eq, assert_optimized_plan_with_rules, test_table_scan,
259+
test_table_scan_fields, test_table_scan_with_name,
261260
};
262261

263262
use super::*;
@@ -266,33 +265,20 @@ mod tests {
266265
assert_optimized_plan_eq(Arc::new(PropagateEmptyRelation::new()), plan, expected)
267266
}
268267

269-
fn assert_together_optimized_plan_eq(
270-
plan: LogicalPlan,
271-
expected: &str,
272-
) -> Result<()> {
273-
assert_optimized_plan_eq_with_rules(
274-
vec![
275-
Arc::new(EliminateFilter::new()),
276-
Arc::new(EliminateNestedUnion::new()),
277-
Arc::new(PropagateEmptyRelation::new()),
278-
],
279-
plan,
280-
expected,
281-
)
282-
}
283-
284-
fn assert_together_optimized_plan_ne(
268+
fn assert_together_optimized_plan(
285269
plan: LogicalPlan,
286270
expected: &str,
271+
eq: bool,
287272
) -> Result<()> {
288-
assert_optimized_plan_ne_with_rules(
273+
assert_optimized_plan_with_rules(
289274
vec![
290275
Arc::new(EliminateFilter::new()),
291276
Arc::new(EliminateNestedUnion::new()),
292277
Arc::new(PropagateEmptyRelation::new()),
293278
],
294279
plan,
295280
expected,
281+
eq,
296282
)
297283
}
298284

@@ -328,7 +314,7 @@ mod tests {
328314
.build()?;
329315

330316
let expected = "EmptyRelation";
331-
assert_together_optimized_plan_eq(plan, expected)
317+
assert_together_optimized_plan(plan, expected, true)
332318
}
333319

334320
#[test]
@@ -341,7 +327,7 @@ mod tests {
341327
let plan = LogicalPlanBuilder::from(left).union(right)?.build()?;
342328

343329
let expected = "TableScan: test";
344-
assert_together_optimized_plan_eq(plan, expected)
330+
assert_together_optimized_plan(plan, expected, true)
345331
}
346332

347333
#[test]
@@ -366,7 +352,7 @@ mod tests {
366352
let expected = "Union\
367353
\n TableScan: test1\
368354
\n TableScan: test4";
369-
assert_together_optimized_plan_eq(plan, expected)
355+
assert_together_optimized_plan(plan, expected, true)
370356
}
371357

372358
#[test]
@@ -391,7 +377,7 @@ mod tests {
391377
.build()?;
392378

393379
let expected = "EmptyRelation";
394-
assert_together_optimized_plan_eq(plan, expected)
380+
assert_together_optimized_plan(plan, expected, true)
395381
}
396382

397383
#[test]
@@ -418,7 +404,7 @@ mod tests {
418404
let expected = "Union\
419405
\n TableScan: test2\
420406
\n TableScan: test3";
421-
assert_together_optimized_plan_eq(plan, expected)
407+
assert_together_optimized_plan(plan, expected, true)
422408
}
423409

424410
#[test]
@@ -431,7 +417,7 @@ mod tests {
431417
let plan = LogicalPlanBuilder::from(left).union(right)?.build()?;
432418

433419
let expected = "TableScan: test";
434-
assert_together_optimized_plan_eq(plan, expected)
420+
assert_together_optimized_plan(plan, expected, true)
435421
}
436422

437423
#[test]
@@ -446,7 +432,7 @@ mod tests {
446432
.build()?;
447433

448434
let expected = "EmptyRelation";
449-
assert_together_optimized_plan_eq(plan, expected)
435+
assert_together_optimized_plan(plan, expected, true)
450436
}
451437

452438
fn empty_left_and_right_lp_empty(
@@ -486,12 +472,7 @@ mod tests {
486472
.build()?;
487473

488474
let expected = "EmptyRelation";
489-
490-
if eq {
491-
assert_together_optimized_plan_eq(plan, expected)
492-
} else {
493-
assert_together_optimized_plan_ne(plan, expected)
494-
}
475+
assert_together_optimized_plan(plan, expected, eq)
495476
}
496477

497478
#[test]
@@ -580,6 +561,6 @@ mod tests {
580561
let expected = "Projection: a, b, c\
581562
\n TableScan: test";
582563

583-
assert_together_optimized_plan_eq(plan, expected)
564+
assert_together_optimized_plan(plan, expected, true)
584565
}
585566
}

datafusion/optimizer/src/test/mod.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,19 @@ fn generate_optimized_plan_with_rules(
198198
.expect("failed to optimize plan")
199199
}
200200

201-
pub fn assert_optimized_plan_eq_with_rules(
201+
pub fn assert_optimized_plan_with_rules(
202202
rules: Vec<Arc<dyn OptimizerRule + Send + Sync>>,
203203
plan: LogicalPlan,
204204
expected: &str,
205+
eq: bool,
205206
) -> Result<()> {
206207
let optimized_plan = generate_optimized_plan_with_rules(rules, plan);
207208
let formatted_plan = format!("{optimized_plan:?}");
208-
assert_eq!(formatted_plan, expected);
209-
Ok(())
210-
}
211-
212-
pub fn assert_optimized_plan_ne_with_rules(
213-
rules: Vec<Arc<dyn OptimizerRule + Send + Sync>>,
214-
plan: LogicalPlan,
215-
expected: &str,
216-
) -> Result<()> {
217-
let optimized_plan = generate_optimized_plan_with_rules(rules, plan);
218-
let formatted_plan = format!("{optimized_plan:?}");
219-
assert_ne!(formatted_plan, expected);
209+
if eq {
210+
assert_eq!(formatted_plan, expected);
211+
} else {
212+
assert_ne!(formatted_plan, expected);
213+
}
220214
Ok(())
221215
}
222216

0 commit comments

Comments
 (0)