avantgardnerio commented on code in PR #4902:
URL: https://github.com/apache/arrow-datafusion/pull/4902#discussion_r1071498071
##########
datafusion/sql/src/statement.rs:
##########
@@ -505,6 +533,192 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}))
}
+ fn delete_to_plan(
+ &self,
+ table_factor: TableFactor,
+ predicate_expr: Option<Expr>,
+ ) -> Result<LogicalPlan> {
+ let table_name = match &table_factor {
+ TableFactor::Table { name, .. } => name.clone(),
+ _ => Err(DataFusionError::Plan(
+ "Unsupported table type for delete!".to_string(),
+ ))?,
+ };
+
+ // Do a table lookup to verify the table exists
+ let table_ref = object_name_to_table_reference(table_name.clone())?;
+ let provider = self
+ .schema_provider
+ .get_table_provider((&table_ref).into())?;
+ let schema = (*provider.schema()).clone();
+ let schema = DFSchema::try_from(schema)?;
+ let scan =
+ LogicalPlanBuilder::scan(table_name.to_string(), provider,
None)?.build()?;
+ let mut planner_context = PlannerContext::new();
+
+ let source = match predicate_expr {
+ None => scan,
+ Some(predicate_expr) => {
+ let filter_expr =
+ self.sql_to_expr(predicate_expr, &schema, &mut
planner_context)?;
+ let schema = Arc::new(schema.clone());
+ let mut using_columns = HashSet::new();
+ expr_to_columns(&filter_expr, &mut using_columns)?;
+ let filter_expr = normalize_col_with_schemas(
+ filter_expr,
+ &[&schema],
+ &[using_columns],
+ )?;
+ LogicalPlan::Filter(Filter::try_new(filter_expr,
Arc::new(scan))?)
+ }
+ };
+
+ let plan = LogicalPlan::Write(WriteRel {
+ table_name: table_ref,
+ table_schema: schema.into(),
+ op: WriteOp::Delete,
+ input: Arc::new(source),
+ });
+ Ok(plan)
+ }
+
+ fn update_to_plan(
Review Comment:
Reflecting on what I just said, I think insert should have the projection
too - I'll do another push.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]