(&self, truncate: &Truncate)
| 1099 | } |
| 1100 | |
| 1101 | async fn handle_truncate_table(&self, truncate: &Truncate) -> DFResult<DataFrame> { |
| 1102 | if truncate.table_names.len() > 1 { |
| 1103 | return Err(DataFusionError::Plan( |
| 1104 | "TRUNCATE TABLE does not support multiple tables".to_string(), |
| 1105 | )); |
| 1106 | } |
| 1107 | let target = truncate.table_names.first().ok_or_else(|| { |
| 1108 | DataFusionError::Plan("TRUNCATE TABLE requires a table name".to_string()) |
| 1109 | })?; |
| 1110 | let (catalog, _catalog_name, identifier) = self.resolve_catalog_and_table(&target.name)?; |
| 1111 | let table = match catalog.get_table(&identifier).await { |
| 1112 | Ok(t) => t, |
| 1113 | Err(e) if truncate.if_exists && is_table_not_exist(&e) => { |
| 1114 | return ok_result(&self.ctx); |
| 1115 | } |
| 1116 | Err(e) => return Err(to_datafusion_error(e)), |
| 1117 | }; |
| 1118 | |
| 1119 | let wb = table.new_write_builder(); |
| 1120 | let commit = wb.new_commit(); |
| 1121 | |
| 1122 | if let Some(partitions) = &truncate.partitions { |
| 1123 | if partitions.is_empty() { |
| 1124 | return Err(DataFusionError::Plan( |
| 1125 | "PARTITION clause requires at least one column = value".to_string(), |
| 1126 | )); |
| 1127 | } |
| 1128 | let partition_values = parse_partition_values( |
| 1129 | partitions, |
| 1130 | table.schema().fields(), |
| 1131 | table.schema().partition_keys(), |
| 1132 | )?; |
| 1133 | commit |
| 1134 | .truncate_partitions(partition_values) |
| 1135 | .await |
| 1136 | .map_err(to_datafusion_error)?; |
| 1137 | return ok_result(&self.ctx); |
| 1138 | } |
| 1139 | |
| 1140 | commit.truncate_table().await.map_err(to_datafusion_error)?; |
| 1141 | ok_result(&self.ctx) |
| 1142 | } |
| 1143 | |
| 1144 | async fn handle_create_view(&self, create_view: &CreateView) -> DFResult<DataFrame> { |
| 1145 | if create_view.materialized { |
no test coverage detected