Skip to content

feat: add basic MemTable MERGE INTO support - #24195

Open
wirybeaver wants to merge 1 commit into
apache:mainfrom
wirybeaver:mergeFollowup
Open

feat: add basic MemTable MERGE INTO support#24195
wirybeaver wants to merge 1 commit into
apache:mainfrom
wirybeaver:mergeFollowup

Conversation

@wirybeaver

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Follow-up to the MERGE INTO review in #22988. No separate issue.

Rationale for this change

MERGE INTO could be planned, but the built-in in-memory table provider could not execute it, and EXPLAIN only showed op=[MergeInto] without the ON condition or WHEN actions. This made the new SQL surface hard to exercise end-to-end with the default provider.

What changes are included in this PR?

  • Adds display helpers for MERGE INTO operations, clauses, and actions, and includes ON / WHEN ... THEN ... details in text and JSON logical plan output.
  • Implements basic MemTable MERGE INTO execution for matched update/delete, not-matched insert, and not-matched-by-source update/delete.
  • Handles first matching clause semantics, NULL predicates as false, duplicate source matches for a target row as an error before mutation, insert column subsets with defaults or typed NULLs, expression casts to target column types, affected-row counts, and sort-order reset.
  • Documents MERGE INTO syntax, provider caveats, and currently unsupported planner syntax.
  • Extends sqllogictests and Rust tests for planning, display, execution, NULL/no-op predicates, defaults, and duplicate-match errors.

Are these changes tested?

Yes:

  • cargo fmt --all
  • cargo test -p datafusion-expr
  • cargo test -p datafusion-catalog
  • cargo test -p datafusion --test core_integration merge_into -- --nocapture
  • cargo test -p datafusion-sql plan_merge_into_canonicalizes_qualifiers_and_preserves_quoted_columns -- --nocapture
  • cargo test --profile=ci --test sqllogictests -- merge_into.slt --nocapture
  • ./ci/scripts/doc_prettier_check.sh --write --allow-dirty
  • cargo clippy --all-targets --all-features -- -D warnings

Note: the plan mentioned cargo test -p datafusion --test sql, but this repository does not currently have a sql test target; the relevant MERGE SQL tests live under core_integration.

Are there any user-facing changes?

Yes. MemTable now supports basic MERGE INTO, and EXPLAIN output for MERGE INTO includes the merge condition and clauses. There are no public API signature changes.

@github-actions github-actions Bot added documentation Improvements or additions to documentation sql SQL Planner logical-expr Logical plan and expressions core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) catalog Related to the catalog crate labels Aug 9, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.35657% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.04%. Comparing base (eec8b94) to head (4e823ba).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/catalog/src/memory/table.rs 81.06% 32 Missing and 25 partials ⚠️
datafusion/expr/src/logical_plan/dml.rs 69.09% 3 Missing and 14 partials ⚠️
datafusion/expr/src/logical_plan/plan.rs 60.00% 0 Missing and 2 partials ⚠️
datafusion/expr/src/logical_plan/display.rs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24195      +/-   ##
==========================================
- Coverage   81.05%   81.04%   -0.01%     
==========================================
  Files        1106     1106              
  Lines      382287   382658     +371     
  Branches   382287   382658     +371     
==========================================
+ Hits       309851   310136     +285     
- Misses      54121    54162      +41     
- Partials    18315    18360      +45     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

catalog Related to the catalog crate core Core DataFusion crate documentation Improvements or additions to documentation logical-expr Logical plan and expressions sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants