File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ pub enum WriteOp {
119
119
Delete ,
120
120
Update ,
121
121
Ctas ,
122
+ Truncate ,
122
123
}
123
124
124
125
impl WriteOp {
@@ -130,6 +131,7 @@ impl WriteOp {
130
131
WriteOp :: Delete => "Delete" ,
131
132
WriteOp :: Update => "Update" ,
132
133
WriteOp :: Ctas => "Ctas" ,
134
+ WriteOp :: Truncate => "Truncate" ,
133
135
}
134
136
}
135
137
}
Original file line number Diff line number Diff line change @@ -542,7 +542,21 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
542
542
}
543
543
self . update_to_plan ( table, assignments, from, selection)
544
544
}
545
+ Statement :: Truncate {
546
+ table_name,
547
+ partitions,
548
+ table,
549
+ } => {
550
+ if !table {
551
+ plan_err ! ( "Truncate of non-tables not yet supported" ) ?;
552
+ }
553
+
554
+ if partitions. is_some ( ) {
555
+ plan_err ! ( "Partition clause not supported" ) ?;
556
+ }
545
557
558
+ self . truncate_to_plan ( table_name)
559
+ }
546
560
Statement :: Delete ( Delete {
547
561
tables,
548
562
using,
@@ -1499,6 +1513,23 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
1499
1513
Ok ( plan)
1500
1514
}
1501
1515
1516
+ fn truncate_to_plan ( & self , table_name : ObjectName ) -> Result < LogicalPlan > {
1517
+ // Do a table lookup to verify the table exists
1518
+ let table_ref = self . object_name_to_table_reference ( table_name. clone ( ) ) ?;
1519
+ let table_source = self . context_provider . get_table_source ( table_ref. clone ( ) ) ?;
1520
+ let schema = ( * table_source. schema ( ) ) . clone ( ) ;
1521
+ let schema = DFSchema :: try_from ( schema) ?;
1522
+ let scan = LogicalPlanBuilder :: empty ( false ) . build ( ) ?;
1523
+
1524
+ let plan = LogicalPlan :: Dml ( DmlStatement :: new (
1525
+ table_ref,
1526
+ schema. into ( ) ,
1527
+ WriteOp :: Truncate ,
1528
+ Arc :: new ( scan) ,
1529
+ ) ) ;
1530
+ Ok ( plan)
1531
+ }
1532
+
1502
1533
fn show_columns_to_plan (
1503
1534
& self ,
1504
1535
extended : bool ,
You can’t perform that action at this time.
0 commit comments