(
&self,
table: TableWithJoins,
assignments: &[Assignment],
from: Option<TableWithJoins>,
predicate_expr: Option<SQLExpr>,
)
| 2241 | } |
| 2242 | |
| 2243 | fn update_to_plan( |
| 2244 | &self, |
| 2245 | table: TableWithJoins, |
| 2246 | assignments: &[Assignment], |
| 2247 | from: Option<TableWithJoins>, |
| 2248 | predicate_expr: Option<SQLExpr>, |
| 2249 | ) -> Result<LogicalPlan> { |
| 2250 | let (table_name, table_alias) = match &table.relation { |
| 2251 | TableFactor::Table { name, alias, .. } => (name.clone(), alias.clone()), |
| 2252 | _ => plan_err!("Cannot update non-table relation!")?, |
| 2253 | }; |
| 2254 | |
| 2255 | // Do a table lookup to verify the table exists |
| 2256 | let table_name = self.object_name_to_table_reference(table_name)?; |
| 2257 | let table_source = self.context_provider.get_table_source(table_name.clone())?; |
| 2258 | let table_schema = Arc::new(DFSchema::try_from_qualified_schema( |
| 2259 | table_name.clone(), |
| 2260 | &table_source.schema(), |
| 2261 | )?); |
| 2262 | |
| 2263 | // Overwrite with assignment expressions |
| 2264 | let mut planner_context = PlannerContext::new(); |
| 2265 | let mut assign_map = assignments |
| 2266 | .iter() |
| 2267 | .map(|assign| { |
| 2268 | let cols = match &assign.target { |
| 2269 | AssignmentTarget::ColumnName(cols) => cols, |
| 2270 | _ => plan_err!("Tuples are not supported")?, |
| 2271 | }; |
| 2272 | let col_name: &Ident = cols |
| 2273 | .0 |
| 2274 | .iter() |
| 2275 | .last() |
| 2276 | .ok_or_else(|| plan_datafusion_err!("Empty column id"))? |
| 2277 | .as_ident() |
| 2278 | .unwrap(); |
| 2279 | // Validate that the assignment target column exists |
| 2280 | table_schema.field_with_unqualified_name(&col_name.value)?; |
| 2281 | Ok((col_name.value.clone(), assign.value.clone())) |
| 2282 | }) |
| 2283 | .collect::<Result<HashMap<String, SQLExpr>>>()?; |
| 2284 | |
| 2285 | // Build scan, join with from table if it exists. |
| 2286 | let mut input_tables = vec![table]; |
| 2287 | input_tables.extend(from); |
| 2288 | let scan = self.plan_from_tables(input_tables, &mut planner_context)?; |
| 2289 | |
| 2290 | // Filter |
| 2291 | let source = match predicate_expr { |
| 2292 | None => scan, |
| 2293 | Some(predicate_expr) => { |
| 2294 | let filter_expr = self.sql_to_expr( |
| 2295 | predicate_expr, |
| 2296 | scan.schema(), |
| 2297 | &mut planner_context, |
| 2298 | )?; |
| 2299 | let mut using_columns = HashSet::new(); |
| 2300 | expr_to_columns(&filter_expr, &mut using_columns)?; |
no test coverage detected