(&self, create_view: &CreateView)
| 1142 | } |
| 1143 | |
| 1144 | async fn handle_create_view(&self, create_view: &CreateView) -> DFResult<DataFrame> { |
| 1145 | if create_view.materialized { |
| 1146 | return Err(DataFusionError::Plan( |
| 1147 | "CREATE MATERIALIZED VIEW is not supported".to_string(), |
| 1148 | )); |
| 1149 | } |
| 1150 | |
| 1151 | let view_name = create_view.name.to_string(); |
| 1152 | let table_ref: TableReference = view_name.as_str().into(); |
| 1153 | let (catalog, database, name) = self.resolve_temp_table_name(table_ref)?; |
| 1154 | |
| 1155 | // Use DataFusion's SQL planner to convert the sqlparser Query into a LogicalPlan |
| 1156 | let query_sql = create_view.query.to_string(); |
| 1157 | let df = self.ctx.sql(&query_sql).await?; |
| 1158 | let logical_plan = df.logical_plan().clone(); |
| 1159 | |
| 1160 | if create_view.temporary { |
| 1161 | if create_view.if_not_exists |
| 1162 | && self.temp_table_exist(format!("{catalog}.{database}.{name}"))? |
| 1163 | { |
| 1164 | return ok_result(&self.ctx); |
| 1165 | } |
| 1166 | // Create a ViewTable and register it as a temp table |
| 1167 | let view_table = datafusion::datasource::ViewTable::new(logical_plan, Some(query_sql)); |
| 1168 | self.register_temp_table(format!("{catalog}.{database}.{name}"), Arc::new(view_table))?; |
| 1169 | ok_result(&self.ctx) |
| 1170 | } else { |
| 1171 | Err(DataFusionError::Plan( |
| 1172 | "CREATE VIEW (non-temporary) is not supported. Use CREATE TEMPORARY VIEW instead." |
| 1173 | .to_string(), |
| 1174 | )) |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | async fn handle_drop_partitions( |
| 1179 | &self, |
no test coverage detected