71
71
/// Identifier name, in the originally quoted form (e.g. `"id"`)
72
72
pub type Ident = String ;
73
73
74
+ /// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
75
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
76
+ pub struct ObjectName ( pub Vec < Ident > ) ;
77
+
78
+ impl fmt:: Display for ObjectName {
79
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
80
+ write ! ( f, "{}" , display_separated( & self . 0 , "." ) )
81
+ }
82
+ }
83
+
74
84
/// An SQL expression of any type.
75
85
///
76
86
/// The parser does not distinguish between expressions of different types
@@ -165,12 +175,9 @@ pub enum Expr {
165
175
impl fmt:: Display for Expr {
166
176
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
167
177
match self {
168
- Expr :: Identifier ( s) => write ! ( f , "{}" , s) ,
178
+ Expr :: Identifier ( s) => f . write_str ( s) ,
169
179
Expr :: Wildcard => f. write_str ( "*" ) ,
170
- Expr :: QualifiedWildcard ( q) => {
171
- write ! ( f, "{}" , display_separated( q, "." ) ) ?;
172
- f. write_str ( ".*" )
173
- }
180
+ Expr :: QualifiedWildcard ( q) => write ! ( f, "{}.*" , display_separated( q, "." ) ) ,
174
181
Expr :: CompoundIdentifier ( s) => write ! ( f, "{}" , display_separated( s, "." ) ) ,
175
182
Expr :: IsNull ( ast) => write ! ( f, "{} IS NULL" , ast) ,
176
183
Expr :: IsNotNull ( ast) => write ! ( f, "{} IS NOT NULL" , ast) ,
@@ -285,11 +292,16 @@ impl fmt::Display for WindowSpec {
285
292
286
293
/// Specifies the data processed by a window function, e.g.
287
294
/// `RANGE UNBOUNDED PRECEDING` or `ROWS BETWEEN 5 PRECEDING AND CURRENT ROW`.
295
+ ///
296
+ /// Note: The parser does not validate the specified bounds; the caller should
297
+ /// reject invalid bounds like `ROWS UNBOUNDED FOLLOWING` before execution.
288
298
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
289
299
pub struct WindowFrame {
290
300
pub units : WindowFrameUnits ,
291
301
pub start_bound : WindowFrameBound ,
292
- /// The right bound of the `BETWEEN .. AND` clause.
302
+ /// The right bound of the `BETWEEN .. AND` clause. The end bound of `None`
303
+ /// indicates the shorthand form (e.g. `ROWS 1 PRECEDING`), which must
304
+ /// behave the same as `end_bound = WindowFrameBound::CurrentRow`.
293
305
pub end_bound : Option < WindowFrameBound > ,
294
306
// TBD: EXCLUDE
295
307
}
@@ -327,14 +339,14 @@ impl FromStr for WindowFrameUnits {
327
339
}
328
340
}
329
341
342
+ /// Specifies [WindowFrame]'s `start_bound` and `end_bound`
330
343
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
331
344
pub enum WindowFrameBound {
332
345
/// `CURRENT ROW`
333
346
CurrentRow ,
334
347
/// `<N> PRECEDING` or `UNBOUNDED PRECEDING`
335
348
Preceding ( Option < u64 > ) ,
336
- /// `<N> FOLLOWING` or `UNBOUNDED FOLLOWING`. This can only appear in
337
- /// [WindowFrame::end_bound].
349
+ /// `<N> FOLLOWING` or `UNBOUNDED FOLLOWING`.
338
350
Following ( Option < u64 > ) ,
339
351
}
340
352
@@ -416,11 +428,16 @@ pub enum Statement {
416
428
name : ObjectName ,
417
429
operation : AlterTableOperation ,
418
430
} ,
419
- /// DROP TABLE
431
+ /// DROP
420
432
Drop {
433
+ /// The type of the object to drop: TABLE, VIEW, etc.
421
434
object_type : ObjectType ,
435
+ /// An optional `IF EXISTS` clause. (Non-standard.)
422
436
if_exists : bool ,
437
+ /// One or more objects to drop. (ANSI SQL requires exactly one.)
423
438
names : Vec < ObjectName > ,
439
+ /// Whether `CASCADE` was specified. This will be `false` when
440
+ /// `RESTRICT` or no drop behavior at all was specified.
424
441
cascade : bool ,
425
442
} ,
426
443
/// `{ BEGIN [ TRANSACTION | WORK ] | START TRANSACTION } ...`
@@ -596,16 +613,6 @@ impl fmt::Display for Statement {
596
613
}
597
614
}
598
615
599
- /// A name of a table, view, custom type, etc., possibly multi-part, i.e. db.schema.obj
600
- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
601
- pub struct ObjectName ( pub Vec < Ident > ) ;
602
-
603
- impl fmt:: Display for ObjectName {
604
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
605
- write ! ( f, "{}" , display_separated( & self . 0 , "." ) )
606
- }
607
- }
608
-
609
616
/// SQL assignment `foo = expr` as used in SQLUpdate
610
617
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
611
618
pub struct Assignment {
@@ -660,19 +667,15 @@ pub enum FileFormat {
660
667
impl fmt:: Display for FileFormat {
661
668
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
662
669
use self :: FileFormat :: * ;
663
- write ! (
664
- f,
665
- "{}" ,
666
- match self {
667
- TEXTFILE => "TEXTFILE" ,
668
- SEQUENCEFILE => "SEQUENCEFILE" ,
669
- ORC => "ORC" ,
670
- PARQUET => "PARQUET" ,
671
- AVRO => "AVRO" ,
672
- RCFILE => "RCFILE" ,
673
- JSONFILE => "TEXTFILE" ,
674
- }
675
- )
670
+ f. write_str ( match self {
671
+ TEXTFILE => "TEXTFILE" ,
672
+ SEQUENCEFILE => "SEQUENCEFILE" ,
673
+ ORC => "ORC" ,
674
+ PARQUET => "PARQUET" ,
675
+ AVRO => "AVRO" ,
676
+ RCFILE => "RCFILE" ,
677
+ JSONFILE => "TEXTFILE" ,
678
+ } )
676
679
}
677
680
}
678
681
@@ -707,14 +710,10 @@ pub enum ObjectType {
707
710
708
711
impl fmt:: Display for ObjectType {
709
712
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
710
- write ! (
711
- f,
712
- "{}" ,
713
- match self {
714
- ObjectType :: Table => "TABLE" ,
715
- ObjectType :: View => "VIEW" ,
716
- }
717
- )
713
+ f. write_str ( match self {
714
+ ObjectType :: Table => "TABLE" ,
715
+ ObjectType :: View => "VIEW" ,
716
+ } )
718
717
}
719
718
}
720
719
@@ -740,7 +739,7 @@ impl fmt::Display for TransactionMode {
740
739
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
741
740
use TransactionMode :: * ;
742
741
match self {
743
- AccessMode ( access_mode) => write ! ( f, "{}" , access_mode. to_string ( ) ) ,
742
+ AccessMode ( access_mode) => write ! ( f, "{}" , access_mode) ,
744
743
IsolationLevel ( iso_level) => write ! ( f, "ISOLATION LEVEL {}" , iso_level) ,
745
744
}
746
745
}
@@ -755,14 +754,10 @@ pub enum TransactionAccessMode {
755
754
impl fmt:: Display for TransactionAccessMode {
756
755
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
757
756
use TransactionAccessMode :: * ;
758
- write ! (
759
- f,
760
- "{}" ,
761
- match self {
762
- ReadOnly => "READ ONLY" ,
763
- ReadWrite => "READ WRITE" ,
764
- }
765
- )
757
+ f. write_str ( match self {
758
+ ReadOnly => "READ ONLY" ,
759
+ ReadWrite => "READ WRITE" ,
760
+ } )
766
761
}
767
762
}
768
763
@@ -777,15 +772,11 @@ pub enum TransactionIsolationLevel {
777
772
impl fmt:: Display for TransactionIsolationLevel {
778
773
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
779
774
use TransactionIsolationLevel :: * ;
780
- write ! (
781
- f,
782
- "{}" ,
783
- match self {
784
- ReadUncommitted => "READ UNCOMMITTED" ,
785
- ReadCommitted => "READ COMMITTED" ,
786
- RepeatableRead => "REPEATABLE READ" ,
787
- Serializable => "SERIALIZABLE" ,
788
- }
789
- )
775
+ f. write_str ( match self {
776
+ ReadUncommitted => "READ UNCOMMITTED" ,
777
+ ReadCommitted => "READ COMMITTED" ,
778
+ RepeatableRead => "REPEATABLE READ" ,
779
+ Serializable => "SERIALIZABLE" ,
780
+ } )
790
781
}
791
782
}
0 commit comments