Skip to content

Commit 2c6eada

Browse files
committed
Add merge_into hook to TableProvider trait
Add merge_into async method to TableProvider trait for MERGE INTO DML support. The method accepts: - source: ExecutionPlan representing the USING clause - on: Expr representing the ON join condition - clauses: Vec<MergeIntoClause> for WHEN MATCHED/NOT MATCHED actions Default implementation returns not_impl_err for tables that don't support MERGE INTO operations.
1 parent 96a6096 commit 2c6eada

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

datafusion/catalog/src/table.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use datafusion_common::{Result, internal_err};
2828
use datafusion_expr::Expr;
2929
use datafusion_expr::statistics::StatisticsRequest;
3030

31-
use datafusion_expr::dml::InsertOp;
31+
use datafusion_expr::dml::{InsertOp, MergeIntoClause};
3232
use datafusion_expr::{
3333
CreateExternalTable, LogicalPlan, TableProviderFilterPushDown, TableType,
3434
};
@@ -379,6 +379,23 @@ pub trait TableProvider: Any + Debug + Sync + Send {
379379
async fn truncate(&self, _state: &dyn Session) -> Result<Arc<dyn ExecutionPlan>> {
380380
not_impl_err!("TRUNCATE not supported for {} table", self.table_type())
381381
}
382+
383+
/// Merge rows from a source into this table.
384+
///
385+
/// The `source` is an [`ExecutionPlan`] representing the USING clause.
386+
/// The `on` condition is the join predicate from the ON clause.
387+
/// The `clauses` describe the WHEN MATCHED / WHEN NOT MATCHED actions.
388+
///
389+
/// Returns an [`ExecutionPlan`] producing a single row with `count` (UInt64).
390+
async fn merge_into(
391+
&self,
392+
_state: &dyn Session,
393+
_source: Arc<dyn ExecutionPlan>,
394+
_on: Expr,
395+
_clauses: Vec<MergeIntoClause>,
396+
) -> Result<Arc<dyn ExecutionPlan>> {
397+
not_impl_err!("MERGE INTO not supported for {} table", self.table_type())
398+
}
382399
}
383400

384401
impl dyn TableProvider {

0 commit comments

Comments
 (0)