Skip to content

Commit 1d17ffb

Browse files
committed
test: improve implementation rule coverage
1 parent 973e4ff commit 1d17ffb

1 file changed

Lines changed: 44 additions & 156 deletions

File tree

  • src/optimizer/rule/implementation

src/optimizer/rule/implementation/mod.rs

Lines changed: 44 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -256,165 +256,43 @@ impl ImplementationRule for ImplementationRuleImpl {
256256
loader: &StatisticMetaLoader<'_>,
257257
best_physical_option: &mut BestPhysicalOption,
258258
) -> Result<(), DatabaseError> {
259+
macro_rules! update {
260+
($implementation:expr) => {
261+
$implementation.update_best_option(operator, arena, loader, best_physical_option)?
262+
};
263+
}
264+
259265
match self {
260-
ImplementationRuleImpl::GroupByAggregate => GroupByAggregateImplementation
261-
.update_best_option(operator, arena, loader, best_physical_option)?,
262-
ImplementationRuleImpl::SimpleAggregate => SimpleAggregateImplementation
263-
.update_best_option(operator, arena, loader, best_physical_option)?,
264-
ImplementationRuleImpl::Dummy => DummyImplementation.update_best_option(
265-
operator,
266-
arena,
267-
loader,
268-
best_physical_option,
269-
)?,
270-
ImplementationRuleImpl::Filter => FilterImplementation.update_best_option(
271-
operator,
272-
arena,
273-
loader,
274-
best_physical_option,
275-
)?,
276-
ImplementationRuleImpl::HashJoin => JoinImplementation.update_best_option(
277-
operator,
278-
arena,
279-
loader,
280-
best_physical_option,
281-
)?,
282-
ImplementationRuleImpl::Limit => LimitImplementation.update_best_option(
283-
operator,
284-
arena,
285-
loader,
286-
best_physical_option,
287-
)?,
288-
ImplementationRuleImpl::MarkApply => MarkApplyImplementation.update_best_option(
289-
operator,
290-
arena,
291-
loader,
292-
best_physical_option,
293-
)?,
294-
ImplementationRuleImpl::Projection => ProjectionImplementation.update_best_option(
295-
operator,
296-
arena,
297-
loader,
298-
best_physical_option,
299-
)?,
300-
ImplementationRuleImpl::ScalarApply => ScalarApplyImplementation.update_best_option(
301-
operator,
302-
arena,
303-
loader,
304-
best_physical_option,
305-
)?,
306-
ImplementationRuleImpl::ScalarSubquery => ScalarSubqueryImplementation
307-
.update_best_option(operator, arena, loader, best_physical_option)?,
308-
ImplementationRuleImpl::SeqScan => SeqScanImplementation.update_best_option(
309-
operator,
310-
arena,
311-
loader,
312-
best_physical_option,
313-
)?,
314-
ImplementationRuleImpl::IndexScan => IndexScanImplementation.update_best_option(
315-
operator,
316-
arena,
317-
loader,
318-
best_physical_option,
319-
)?,
320-
ImplementationRuleImpl::FunctionScan => FunctionScanImplementation.update_best_option(
321-
operator,
322-
arena,
323-
loader,
324-
best_physical_option,
325-
)?,
326-
ImplementationRuleImpl::Sort => SortImplementation.update_best_option(
327-
operator,
328-
arena,
329-
loader,
330-
best_physical_option,
331-
)?,
332-
ImplementationRuleImpl::TopK => TopKImplementation.update_best_option(
333-
operator,
334-
arena,
335-
loader,
336-
best_physical_option,
337-
)?,
338-
ImplementationRuleImpl::Values => ValuesImplementation.update_best_option(
339-
operator,
340-
arena,
341-
loader,
342-
best_physical_option,
343-
)?,
266+
ImplementationRuleImpl::GroupByAggregate => update!(GroupByAggregateImplementation),
267+
ImplementationRuleImpl::SimpleAggregate => update!(SimpleAggregateImplementation),
268+
ImplementationRuleImpl::Dummy => update!(DummyImplementation),
269+
ImplementationRuleImpl::Filter => update!(FilterImplementation),
270+
ImplementationRuleImpl::HashJoin => update!(JoinImplementation),
271+
ImplementationRuleImpl::Limit => update!(LimitImplementation),
272+
ImplementationRuleImpl::MarkApply => update!(MarkApplyImplementation),
273+
ImplementationRuleImpl::Projection => update!(ProjectionImplementation),
274+
ImplementationRuleImpl::ScalarApply => update!(ScalarApplyImplementation),
275+
ImplementationRuleImpl::ScalarSubquery => update!(ScalarSubqueryImplementation),
276+
ImplementationRuleImpl::SeqScan => update!(SeqScanImplementation),
277+
ImplementationRuleImpl::IndexScan => update!(IndexScanImplementation),
278+
ImplementationRuleImpl::FunctionScan => update!(FunctionScanImplementation),
279+
ImplementationRuleImpl::Sort => update!(SortImplementation),
280+
ImplementationRuleImpl::TopK => update!(TopKImplementation),
281+
ImplementationRuleImpl::Values => update!(ValuesImplementation),
344282
#[cfg(feature = "copy")]
345-
ImplementationRuleImpl::CopyFromFile => CopyFromFileImplementation.update_best_option(
346-
operator,
347-
arena,
348-
loader,
349-
best_physical_option,
350-
)?,
283+
ImplementationRuleImpl::CopyFromFile => update!(CopyFromFileImplementation),
351284
#[cfg(feature = "copy")]
352-
ImplementationRuleImpl::CopyToFile => CopyToFileImplementation.update_best_option(
353-
operator,
354-
arena,
355-
loader,
356-
best_physical_option,
357-
)?,
358-
ImplementationRuleImpl::Delete => DeleteImplementation.update_best_option(
359-
operator,
360-
arena,
361-
loader,
362-
best_physical_option,
363-
)?,
364-
ImplementationRuleImpl::Insert => InsertImplementation.update_best_option(
365-
operator,
366-
arena,
367-
loader,
368-
best_physical_option,
369-
)?,
370-
ImplementationRuleImpl::Update => UpdateImplementation.update_best_option(
371-
operator,
372-
arena,
373-
loader,
374-
best_physical_option,
375-
)?,
376-
ImplementationRuleImpl::AddColumn => AddColumnImplementation.update_best_option(
377-
operator,
378-
arena,
379-
loader,
380-
best_physical_option,
381-
)?,
382-
ImplementationRuleImpl::ChangeColumn => ChangeColumnImplementation.update_best_option(
383-
operator,
384-
arena,
385-
loader,
386-
best_physical_option,
387-
)?,
388-
ImplementationRuleImpl::CreateTable => CreateTableImplementation.update_best_option(
389-
operator,
390-
arena,
391-
loader,
392-
best_physical_option,
393-
)?,
394-
ImplementationRuleImpl::DropColumn => DropColumnImplementation.update_best_option(
395-
operator,
396-
arena,
397-
loader,
398-
best_physical_option,
399-
)?,
400-
ImplementationRuleImpl::DropTable => DropTableImplementation.update_best_option(
401-
operator,
402-
arena,
403-
loader,
404-
best_physical_option,
405-
)?,
406-
ImplementationRuleImpl::Truncate => TruncateImplementation.update_best_option(
407-
operator,
408-
arena,
409-
loader,
410-
best_physical_option,
411-
)?,
412-
ImplementationRuleImpl::Analyze => AnalyzeImplementation.update_best_option(
413-
operator,
414-
arena,
415-
loader,
416-
best_physical_option,
417-
)?,
285+
ImplementationRuleImpl::CopyToFile => update!(CopyToFileImplementation),
286+
ImplementationRuleImpl::Delete => update!(DeleteImplementation),
287+
ImplementationRuleImpl::Insert => update!(InsertImplementation),
288+
ImplementationRuleImpl::Update => update!(UpdateImplementation),
289+
ImplementationRuleImpl::AddColumn => update!(AddColumnImplementation),
290+
ImplementationRuleImpl::ChangeColumn => update!(ChangeColumnImplementation),
291+
ImplementationRuleImpl::CreateTable => update!(CreateTableImplementation),
292+
ImplementationRuleImpl::DropColumn => update!(DropColumnImplementation),
293+
ImplementationRuleImpl::DropTable => update!(DropTableImplementation),
294+
ImplementationRuleImpl::Truncate => update!(TruncateImplementation),
295+
ImplementationRuleImpl::Analyze => update!(AnalyzeImplementation),
418296
}
419297

420298
Ok(())
@@ -481,6 +359,10 @@ mod tests {
481359
arena: &PlanArena,
482360
) -> Result<PhysicalOption, DatabaseError> {
483361
assert!((rule.pattern().predicate)(operator));
362+
assert_eq!(
363+
ImplementationRuleRootTag::from_operator(operator),
364+
Some(rule.root_tag())
365+
);
484366

485367
let statistics_cache = StatisticsMetaCache::default();
486368
let loader = StatisticMetaLoader::new(&statistics_cache);
@@ -568,6 +450,12 @@ mod tests {
568450
|op| matches!(op, Operator::Values(_)),
569451
PlanImpl::Values,
570452
)?;
453+
assert_sql_rule(
454+
"select * from t1",
455+
ImplementationRuleImpl::SeqScan,
456+
|op| matches!(op, Operator::TableScan(_)),
457+
PlanImpl::SeqScan,
458+
)?;
571459

572460
Ok(())
573461
}

0 commit comments

Comments
 (0)