@@ -5,7 +5,7 @@ use readyset_util::fmt::fmt_with;
5
5
use serde:: { Deserialize , Serialize } ;
6
6
use test_strategy:: Arbitrary ;
7
7
8
- use crate :: { ast:: * , Dialect , DialectDisplay } ;
8
+ use crate :: { ast:: * , AstConversionError , Dialect , DialectDisplay , IntoDialect , TryFromDialect } ;
9
9
10
10
#[ derive( Clone , Debug , Eq , Hash , PartialEq , Serialize , Deserialize , Arbitrary ) ]
11
11
@@ -21,6 +21,42 @@ pub struct TruncateStatement {
21
21
pub cascade : bool ,
22
22
}
23
23
24
+ impl TryFromDialect < sqlparser:: ast:: Statement > for TruncateStatement {
25
+ fn try_from_dialect (
26
+ value : sqlparser:: ast:: Statement ,
27
+ dialect : Dialect ,
28
+ ) -> Result < Self , AstConversionError > {
29
+ if let sqlparser:: ast:: Statement :: Truncate {
30
+ table_names,
31
+ partitions : _,
32
+ table : _,
33
+ // XXX(mvzink): I believe sqlparser is incorrect here; ONLY should be on each table
34
+ // target, not the whole statement. We interpret it as applying to all tables, but
35
+ // should probably upstream a fix (or verify that sqlparser is correct).
36
+ only,
37
+ identity,
38
+ cascade,
39
+ on_cluster : _,
40
+ } = value
41
+ {
42
+ let tables = table_names
43
+ . into_iter ( )
44
+ . map ( |table| TruncateTable {
45
+ relation : table. name . into_dialect ( dialect) ,
46
+ only,
47
+ } )
48
+ . collect ( ) ;
49
+ Ok ( Self {
50
+ tables,
51
+ restart_identity : identity == Some ( sqlparser:: ast:: TruncateIdentityOption :: Restart ) ,
52
+ cascade : cascade == Some ( sqlparser:: ast:: CascadeOption :: Cascade ) ,
53
+ } )
54
+ } else {
55
+ failed ! ( "Should only be called on TRUNCATE statement, got {value:?}" )
56
+ }
57
+ }
58
+ }
59
+
24
60
impl DialectDisplay for TruncateStatement {
25
61
fn display ( & self , dialect : Dialect ) -> impl fmt:: Display + ' _ {
26
62
fmt_with ( move |f| {
0 commit comments