Skip to content

fix(datafusion): map column-less MERGE INSERT VALUES by position - #984

Open
jackylee-ch wants to merge 1 commit into
apache:mainfrom
jackylee-ch:fix/merge-into-insert-without-columns
Open

jackylee-ch wants to merge 1 commit into
apache:mainfrom
jackylee-ch:fix/merge-into-insert-without-columns

Conversation

@jackylee-ch

@jackylee-ch jackylee-ch commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

WHEN NOT MATCHED THEN INSERT VALUES (s.a, s.b, ...) without an explicit column list built an empty column->expression map, so insert_select_clause emitted NULL for every target column and dropped the source values. The merge then inserted all-NULL rows (or failed on a non-null column) instead of the source data — silent corruption for a column-less positional INSERT. This form is valid standard SQL (the MERGE INSERT column list is optional) and DataFusion's parser accepts it; Spark's own MERGE grammar, by contrast, requires an explicit column list or INSERT *. The existing MERGE INSERT tests all pass an explicit column list, so this went uncovered.

Map the VALUES to the table's columns by position when no column list is given, and reject a value/column count mismatch. Explicit-column and INSERT * clauses are unchanged.

Added an end-to-end MERGE test using a column-less INSERT; it inserts all-NULL rows before the fix.

`WHEN NOT MATCHED THEN INSERT VALUES (s.a, s.b, ...)` without an explicit
column list built an empty column->expression map, so `insert_select_clause`
emitted `NULL` for every target column and dropped the source values. The
merge then inserted all-NULL rows (or failed on a non-null column) instead of
the source data — silent corruption for a column-less positional INSERT, which
is valid standard SQL (the MERGE INSERT column list is optional) and accepted
by DataFusion's parser.

Map the VALUES to the table's columns by position when no column list is
given, and reject a value/column count mismatch. Explicit-column and
`INSERT *` clauses are unchanged.

Added an end-to-end MERGE test using a column-less INSERT; it inserts all-NULL
rows before the fix.
@jackylee-ch
jackylee-ch force-pushed the fix/merge-into-insert-without-columns branch from 0db0c22 to bdde90b Compare September 30, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant