1010// See the License for the specific language governing permissions and
1111// limitations under the License.
1212
13+ use tracing:: debug;
14+
1315use crate :: coordinator:: analyze:: analysis:: Analysis ;
1416use crate :: coordinator:: plan:: {
1517 CreateFunctionPlan , CreatePythonFunctionPlan , DropFunctionPlan , PlanNode , ShowFunctionsPlan ,
16- StartFunctionPlan , StopFunctionPlan ,
18+ StartFunctionPlan , StopFunctionPlan , StreamingSqlPlan ,
1719} ;
1820use crate :: coordinator:: statement:: {
1921 CreateFunction , CreatePythonFunction , DropFunction , ShowFunctions , StartFunction ,
20- StatementVisitor , StatementVisitorContext , StatementVisitorResult , StopFunction ,
22+ StatementVisitor , StatementVisitorContext , StatementVisitorResult , StopFunction , StreamingSql ,
2123} ;
24+ use crate :: sql:: planner:: StreamSchemaProvider ;
2225
23- #[ derive( Debug , Default ) ]
24- pub struct LogicalPlanVisitor ;
26+ pub struct LogicalPlanVisitor {
27+ schema_provider : StreamSchemaProvider ,
28+ }
2529
2630impl LogicalPlanVisitor {
27- pub fn new ( ) -> Self {
28- Self
31+ pub fn new ( schema_provider : StreamSchemaProvider ) -> Self {
32+ Self { schema_provider }
2933 }
3034
3135 pub fn visit ( & self , analysis : & Analysis ) -> Box < dyn PlanNode > {
@@ -51,7 +55,6 @@ impl StatementVisitor for LogicalPlanVisitor {
5155 let config_source = stmt. get_config_source ( ) . cloned ( ) ;
5256 let extra_props = stmt. get_extra_properties ( ) . clone ( ) ;
5357
54- // Name will be read from config file during execution
5558 StatementVisitorResult :: Plan ( Box :: new ( CreateFunctionPlan :: new (
5659 function_source,
5760 config_source,
@@ -106,4 +109,22 @@ impl StatementVisitor for LogicalPlanVisitor {
106109 config_content,
107110 ) ) )
108111 }
112+
113+ fn visit_streaming_sql (
114+ & self ,
115+ stmt : & StreamingSql ,
116+ _context : & StatementVisitorContext ,
117+ ) -> StatementVisitorResult {
118+ let sql_to_rel = datafusion:: sql:: planner:: SqlToRel :: new ( & self . schema_provider ) ;
119+
120+ match sql_to_rel. sql_statement_to_plan ( stmt. statement . clone ( ) ) {
121+ Ok ( plan) => {
122+ debug ! ( "Logical plan:\n {}" , plan. display_graphviz( ) ) ;
123+ StatementVisitorResult :: Plan ( Box :: new ( StreamingSqlPlan :: new ( plan) ) )
124+ }
125+ Err ( e) => {
126+ panic ! ( "Failed to convert SQL statement to logical plan: {e}" ) ;
127+ }
128+ }
129+ }
109130}
0 commit comments