@@ -475,6 +475,7 @@ pub(crate) fn assert_schema_is_the_same(
475
475
mod tests {
476
476
use std:: sync:: { Arc , Mutex } ;
477
477
478
+ use datafusion_common:: tree_node:: Transformed ;
478
479
use datafusion_common:: { plan_err, DFSchema , DFSchemaRef , Result } ;
479
480
use datafusion_expr:: logical_plan:: EmptyRelation ;
480
481
use datafusion_expr:: { col, lit, LogicalPlan , LogicalPlanBuilder , Projection } ;
@@ -676,13 +677,27 @@ mod tests {
676
677
_: & LogicalPlan ,
677
678
_: & dyn OptimizerConfig ,
678
679
) -> Result < Option < LogicalPlan > > {
679
- let table_scan = test_table_scan ( ) ?;
680
- Ok ( Some ( LogicalPlanBuilder :: from ( table_scan) . build ( ) ?) )
680
+ unreachable ! ( )
681
681
}
682
682
683
683
fn name ( & self ) -> & str {
684
684
"get table_scan rule"
685
685
}
686
+
687
+ fn supports_rewrite ( & self ) -> bool {
688
+ true
689
+ }
690
+
691
+ fn rewrite (
692
+ & self ,
693
+ _plan : LogicalPlan ,
694
+ _config : & dyn OptimizerConfig ,
695
+ ) -> Result < Transformed < LogicalPlan > > {
696
+ let table_scan = test_table_scan ( ) ?;
697
+ Ok ( Transformed :: yes (
698
+ LogicalPlanBuilder :: from ( table_scan) . build ( ) ?,
699
+ ) )
700
+ }
686
701
}
687
702
688
703
/// A goofy rule doing rotation of columns in all projections.
@@ -704,12 +719,32 @@ mod tests {
704
719
impl OptimizerRule for RotateProjectionRule {
705
720
fn try_optimize (
706
721
& self ,
707
- plan : & LogicalPlan ,
722
+ _plan : & LogicalPlan ,
708
723
_: & dyn OptimizerConfig ,
709
724
) -> Result < Option < LogicalPlan > > {
725
+ unreachable ! ( )
726
+ }
727
+
728
+ fn name ( & self ) -> & str {
729
+ "rotate_projection"
730
+ }
731
+
732
+ fn apply_order ( & self ) -> Option < ApplyOrder > {
733
+ Some ( ApplyOrder :: TopDown )
734
+ }
735
+
736
+ fn supports_rewrite ( & self ) -> bool {
737
+ true
738
+ }
739
+
740
+ fn rewrite (
741
+ & self ,
742
+ plan : LogicalPlan ,
743
+ _config : & dyn OptimizerConfig ,
744
+ ) -> Result < Transformed < LogicalPlan > > {
710
745
let projection = match plan {
711
746
LogicalPlan :: Projection ( p) if p. expr . len ( ) >= 2 => p,
712
- _ => return Ok ( None ) ,
747
+ _ => return Ok ( Transformed :: no ( plan ) ) ,
713
748
} ;
714
749
715
750
let mut exprs = projection. expr . clone ( ) ;
@@ -722,18 +757,9 @@ mod tests {
722
757
exprs. rotate_left ( 1 ) ;
723
758
}
724
759
725
- Ok ( Some ( LogicalPlan :: Projection ( Projection :: try_new (
726
- exprs,
727
- projection. input . clone ( ) ,
728
- ) ?) ) )
729
- }
730
-
731
- fn apply_order ( & self ) -> Option < ApplyOrder > {
732
- Some ( ApplyOrder :: TopDown )
733
- }
734
-
735
- fn name ( & self ) -> & str {
736
- "rotate_projection"
760
+ Ok ( Transformed :: yes ( LogicalPlan :: Projection (
761
+ Projection :: try_new ( exprs, projection. input . clone ( ) ) ?,
762
+ ) ) )
737
763
}
738
764
}
739
765
}
0 commit comments