Skip to content

Apache DataFusion SQL Query Engine

Migrate testing optimizer rules to use `rewrite` API (#10576)

张林伟f80794779ef2
diff --git a/datafusion/optimizer/src/optimizer.rs b/datafusion/optimizer/src/optimizer.rs
index e787f56587..8651cfd2cf 100644
--- a/datafusion/optimizer/src/optimizer.rs
+++ b/datafusion/optimizer/src/optimizer.rs
@@ -475,6 +475,7 @@ pub(crate) fn assert_schema_is_the_same(
mod tests {
use std::sync::{Arc, Mutex};
+ use datafusion_common::tree_node::Transformed;
use datafusion_common::{plan_err, DFSchema, DFSchemaRef, Result};
use datafusion_expr::logical_plan::EmptyRelation;
use datafusion_expr::{col, lit, LogicalPlan, LogicalPlanBuilder, Projection};
@@ -676,13 +677,27 @@ mod tests {
_: &LogicalPlan,
_: &dyn OptimizerConfig,
) -> Result<Option<LogicalPlan>> {
- let table_scan = test_table_scan()?;
- Ok(Some(LogicalPlanBuilder::from(table_scan).build()?))
+ unreachable!()
}
fn name(&self) -> &str {
"get table_scan rule"
}
+
+ fn supports_rewrite(&self) -> bool {
+ true
+ }
+
+ fn rewrite(
+ &self,
+ _plan: LogicalPlan,
+ _config: &dyn OptimizerConfig,
+ ) -> Result<Transformed<LogicalPlan>> {
+ let table_scan = test_table_scan()?;
+ Ok(Transformed::yes(
+ LogicalPlanBuilder::from(table_scan).build()?,
+ ))
+ }
}
/// A goofy rule doing rotation of columns in all projections.
@@ -704,12 +719,32 @@ mod tests {
impl OptimizerRule for RotateProjectionRule {
fn try_optimize(
&self,
- plan: &LogicalPlan,
+ _plan: &LogicalPlan,
_: &dyn OptimizerConfig,
) -> Result<Option<LogicalPlan>> {
+ unreachable!()
+ }
+
+ fn name(&self) -> &str {
+ "rotate_projection"
+ }
+
+ fn apply_order(&self) -> Option<ApplyOrder> {
+ Some(ApplyOrder::TopDown)
+ }
+
+ fn supports_rewrite(&self) -> bool {
+ true
+ }
+
+ fn rewrite(
+ &self,
+ plan: LogicalPlan,
+ _config: &dyn OptimizerConfig,
+ ) -> Result<Transformed<LogicalPlan>> {
let projection = match plan {
LogicalPlan::Projection(p) if p.expr.len() >= 2 => p,
- _ => return Ok(None),
+ _ => return Ok(Transformed::no(plan)),
};
let mut exprs = projection.expr.clone();
@@ -722,18 +757,9 @@ mod tests {
exprs.rotate_left(1);
}
- Ok(Some(LogicalPlan::Projection(Projection::try_new(
- exprs,
- projection.input.clone(),
- )?)))
- }
-
- fn apply_order(&self) -> Option<ApplyOrder> {
- Some(ApplyOrder::TopDown)
- }
-
- fn name(&self) -> &str {
- "rotate_projection"
+ Ok(Transformed::yes(LogicalPlan::Projection(
+ Projection::try_new(exprs, projection.input.clone())?,
+ )))
}
}
}
diff --git a/datafusion/proto/proto/datafusion.proto b/datafusion/proto/proto/datafusion.proto
index 1c11e8e50d..73e751c616 100644
--- a/datafusion/proto/proto/datafusion.proto
+++ b/datafusion/proto/proto/datafusion.proto
@@ -1,6 +1,4 @@
/*
-
-
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information