@@ -17,7 +17,7 @@ use datafusion::execution::SessionStateBuilder;
1717use datafusion:: logical_expr:: { Explain , LogicalPlan , PlanType , TableSource , ToStringifiedPlan } ;
1818use datafusion:: physical_plan:: ExecutionPlan ;
1919use datafusion:: physical_planner:: { DefaultPhysicalPlanner , PhysicalPlanner } ;
20- use datafusion:: prelude:: { SessionConfig , SessionContext } ;
20+ use datafusion:: prelude:: { Expr , SessionConfig , SessionContext } ;
2121
2222/// TODO make distinction between relational groups and scalar groups.
2323#[ repr( transparent) ]
@@ -29,7 +29,11 @@ pub struct GroupId(u64);
2929pub struct ExprId ( u64 ) ;
3030
3131mod types;
32- use types:: plan:: logical_plan:: LogicalPlan as OptDLogicalPlan ;
32+ use types:: operator:: logical:: {
33+ LogicalFilterOperator , LogicalJoinOperator , LogicalOperator , LogicalScanOperator ,
34+ } ;
35+ use types:: operator:: ScalarOperator ;
36+ use types:: plan:: logical_plan:: { LogicalLink , LogicalPlan as OptDLogicalPlan , ScalarLink } ;
3337
3438struct OptdOptimizer { }
3539
@@ -38,14 +42,47 @@ pub struct OptdQueryPlanner {
3842}
3943
4044impl OptdQueryPlanner {
41- fn convert_into_optd_logical ( plan_node : LogicalPlan ) -> OptDLogicalPlan {
42- match plan_node {
43- LogicalPlan :: Filter ( filter) => todo ! ( ) ,
44- LogicalPlan :: Join ( join) => todo ! ( ) ,
45- LogicalPlan :: TableScan ( table_scan) => todo ! ( ) ,
45+ fn convert_into_optd_scalar ( predicate_expr : Expr ) -> Arc < ScalarOperator < ScalarLink > > {
46+ // TODO: Implement the conversion logic here
47+ Arc :: new ( ScalarOperator :: new ( ) )
48+ }
49+
50+ fn convert_into_optd_logical ( plan_node : Arc < LogicalPlan > ) -> Arc < LogicalOperator < LogicalLink > > {
51+ match & * plan_node {
52+ LogicalPlan :: Filter ( filter) => {
53+ Arc :: new ( LogicalOperator :: Filter ( LogicalFilterOperator {
54+ child : LogicalLink :: LogicalNode ( Self :: convert_into_optd_logical (
55+ filter. input . clone ( ) ,
56+ ) ) ,
57+ predicate : LogicalLink :: ScalarNode ( Self :: convert_into_optd_scalar (
58+ filter. predicate . clone ( ) ,
59+ ) ) ,
60+ } ) )
61+ }
62+
63+ LogicalPlan :: Join ( join) => Arc :: new ( LogicalOperator :: Join (
64+ ( LogicalJoinOperator {
65+ join_type : ( ) ,
66+ left : LogicalLink :: LogicalNode ( Self :: convert_into_optd_logical (
67+ join. left . clone ( ) ,
68+ ) ) ,
69+ right : LogicalLink :: LogicalNode ( Self :: convert_into_optd_logical (
70+ join. right . clone ( ) ,
71+ ) ) ,
72+ condition : LogicalLink :: ScalarNode ( Arc :: new ( todo ! ( ) ) ) ,
73+ } ) ,
74+ ) ) ,
75+
76+ LogicalPlan :: TableScan ( table_scan) => Arc :: new ( LogicalOperator :: Scan (
77+ ( LogicalScanOperator {
78+ table_name : table_scan. table_name . to_quoted_string ( ) ,
79+ predicate : None , // TODO fix this: there are multiple predicates in the scan but our IR only accepts one
80+ } ) ,
81+ ) ) ,
4682 _ => panic ! ( "OptD does not support this type of query yet" ) ,
4783 }
4884 }
85+
4986 async fn create_physical_plan_inner (
5087 & self ,
5188 logical_plan : & LogicalPlan ,
0 commit comments