1- use std:: any:: Any ;
21use std:: collections:: HashMap ;
32
4- use dyn_clone:: DynClone ;
5-
63use crate :: expression:: Expr ;
74
8- pub enum StatementKind {
9- Select ,
10- Where ,
11- Having ,
12- Limit ,
13- Offset ,
14- OrderBy ,
15- GroupBy ,
16- AggregateFunction ,
17- WindowFunction ,
18- Qualify ,
19- Into ,
20- }
21-
22- dyn_clone:: clone_trait_object!( Statement ) ;
23-
24- pub trait Statement : DynClone {
25- fn kind ( & self ) -> StatementKind ;
26- fn as_any ( & self ) -> & dyn Any ;
5+ pub enum Statement {
6+ Select ( SelectStatement ) ,
7+ Where ( WhereStatement ) ,
8+ Having ( HavingStatement ) ,
9+ Limit ( LimitStatement ) ,
10+ Offset ( OffsetStatement ) ,
11+ OrderBy ( OrderByStatement ) ,
12+ GroupBy ( GroupByStatement ) ,
13+ AggregateFunction ( AggregationsStatement ) ,
14+ WindowFunction ( WindowFunctionsStatement ) ,
15+ Qualify ( QualifyStatement ) ,
16+ Into ( IntoStatement ) ,
2717}
2818
2919#[ derive( Clone ) ]
@@ -72,76 +62,26 @@ pub struct SelectStatement {
7262 pub distinct : Distinct ,
7363}
7464
75- impl Statement for SelectStatement {
76- fn as_any ( & self ) -> & dyn Any {
77- self
78- }
79-
80- fn kind ( & self ) -> StatementKind {
81- StatementKind :: Select
82- }
83- }
84-
8565#[ derive( Clone ) ]
8666pub struct WhereStatement {
8767 pub condition : Box < dyn Expr > ,
8868}
8969
90- impl Statement for WhereStatement {
91- fn as_any ( & self ) -> & dyn Any {
92- self
93- }
94-
95- fn kind ( & self ) -> StatementKind {
96- StatementKind :: Where
97- }
98- }
99-
10070#[ derive( Clone ) ]
10171pub struct HavingStatement {
10272 pub condition : Box < dyn Expr > ,
10373}
10474
105- impl Statement for HavingStatement {
106- fn as_any ( & self ) -> & dyn Any {
107- self
108- }
109-
110- fn kind ( & self ) -> StatementKind {
111- StatementKind :: Having
112- }
113- }
114-
11575#[ derive( Clone ) ]
11676pub struct LimitStatement {
11777 pub count : usize ,
11878}
11979
120- impl Statement for LimitStatement {
121- fn as_any ( & self ) -> & dyn Any {
122- self
123- }
124-
125- fn kind ( & self ) -> StatementKind {
126- StatementKind :: Limit
127- }
128- }
129-
13080#[ derive( Clone ) ]
13181pub struct OffsetStatement {
13282 pub start : Box < dyn Expr > ,
13383}
13484
135- impl Statement for OffsetStatement {
136- fn as_any ( & self ) -> & dyn Any {
137- self
138- }
139-
140- fn kind ( & self ) -> StatementKind {
141- StatementKind :: Offset
142- }
143- }
144-
14585#[ derive( Clone , PartialEq ) ]
14686pub enum SortingOrder {
14787 Ascending ,
@@ -161,32 +101,12 @@ pub struct OrderByStatement {
161101 pub nulls_order_policies : Vec < NullsOrderPolicy > ,
162102}
163103
164- impl Statement for OrderByStatement {
165- fn as_any ( & self ) -> & dyn Any {
166- self
167- }
168-
169- fn kind ( & self ) -> StatementKind {
170- StatementKind :: OrderBy
171- }
172- }
173-
174104#[ derive( Clone ) ]
175105pub struct GroupByStatement {
176106 pub values : Vec < Box < dyn Expr > > ,
177107 pub has_with_roll_up : bool ,
178108}
179109
180- impl Statement for GroupByStatement {
181- fn as_any ( & self ) -> & dyn Any {
182- self
183- }
184-
185- fn kind ( & self ) -> StatementKind {
186- StatementKind :: GroupBy
187- }
188- }
189-
190110#[ derive( Clone ) ]
191111pub struct WindowPartitioningClause {
192112 pub expr : Box < dyn Expr > ,
@@ -229,31 +149,11 @@ pub struct WindowFunctionsStatement {
229149 pub window_values : HashMap < String , WindowValue > ,
230150}
231151
232- impl Statement for WindowFunctionsStatement {
233- fn as_any ( & self ) -> & dyn Any {
234- self
235- }
236-
237- fn kind ( & self ) -> StatementKind {
238- StatementKind :: WindowFunction
239- }
240- }
241-
242152#[ derive( Clone ) ]
243153pub struct QualifyStatement {
244154 pub condition : Box < dyn Expr > ,
245155}
246156
247- impl Statement for QualifyStatement {
248- fn as_any ( & self ) -> & dyn Any {
249- self
250- }
251-
252- fn kind ( & self ) -> StatementKind {
253- StatementKind :: Qualify
254- }
255- }
256-
257157#[ derive( Clone ) ]
258158pub enum AggregateValue {
259159 Expression ( Box < dyn Expr > ) ,
@@ -265,30 +165,10 @@ pub struct AggregationsStatement {
265165 pub aggregations : HashMap < String , AggregateValue > ,
266166}
267167
268- impl Statement for AggregationsStatement {
269- fn as_any ( & self ) -> & dyn Any {
270- self
271- }
272-
273- fn kind ( & self ) -> StatementKind {
274- StatementKind :: AggregateFunction
275- }
276- }
277-
278168#[ derive( Clone ) ]
279169pub struct IntoStatement {
280170 pub file_path : String ,
281171 pub lines_terminated : String ,
282172 pub fields_terminated : String ,
283173 pub enclosed : String ,
284174}
285-
286- impl Statement for IntoStatement {
287- fn as_any ( & self ) -> & dyn Any {
288- self
289- }
290-
291- fn kind ( & self ) -> StatementKind {
292- StatementKind :: Into
293- }
294- }
0 commit comments