Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add SQL Support for MERGE INTO in Presto (engine) #26278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
acarpente-denodo wants to merge 3 commits into prestodb:master
base: master
Choose a base branch
Loading
from acarpente-denodo:feature/20578_SQL_Support_for_MERGE_INTO_(engine)

Conversation

Copy link
Contributor

@acarpente-denodo acarpente-denodo commented Oct 10, 2025
edited
Loading

Description

Engine support for SQL MERGE INTO. The MERGE INTO command inserts or updates rows in a table based on specified conditions.

Syntax:

MERGE INTO target_table [ [ AS ] target_alias ]
USING { source_table | query } [ [ AS ] source_alias ]
ON search_condition
WHEN MATCHED THEN
 UPDATE SET ( column = expression [, ...] )
WHEN NOT MATCHED THEN
 INSERT [ column_list ]
 VALUES (expression, ...)

Example: MERGE INTO usage to update the sales information for existing products and insert the sales information for the new products in the market.

MERGE INTO product_sales AS s
 USING monthly_sales AS ms
 ON s.product_id = ms.product_id
WHEN MATCHED THEN
 UPDATE SET
 sales = sales + ms.sales
 , last_sale = ms.sale_date
 , current_price = ms.price
WHEN NOT MATCHED THEN
 INSERT (product_id, sales, last_sale, current_price)
 VALUES (ms.product_id, ms.sales, ms.sale_date, ms.price)

The Presto engine commit introduces an enum called RowChangeParadigm, which describes how a connector modifies rows. The iceberg connector will utilize the DELETE_ROW_AND_INSERT_ROW paradigm, as it represents an updated row as a combination of a deleted row followed by an inserted row. The CHANGE_ONLY_UPDATED_COLUMNS paradigm is meant for connectors that support updating individual columns of rows.

Note: Changes were made after reviewing the following Trino PR: trinodb/trino#7126
So, this commit is deeply inspired by Trino's implementation.

Motivation and Context

The MERGE INTO statement is commonly used to integrate data from two tables with different contents but similar structures.
For example, the source table could be part of a production transactional system, while the target table might be located in a data warehouse for analytics.
Regularly, MERGE operations are performed to update the analytics warehouse with the latest production data.
You can also use MERGE with tables that have different structures, as long as you can define a condition to match the rows between them.

Test Plan

Automated tests developed in TestSqlParser, TestSqlParserErrorHandling, TestStatementBuilder, AbstractAnalyzerTest, TestAnalyzer, and TestClassLoaderSafeWrappers classes.

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

== RELEASE NOTES ==
General Changes
* Add support for the MERGE INTO command in the Presto engine.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @acarpente-denodo, your pull request is larger than the review limit of 150000 diff characters

sourcery-ai[bot] reacted with thumbs up emoji sourcery-ai[bot] reacted with thumbs down emoji
@acarpente-denodo acarpente-denodo changed the title (削除) Draft: feat: Add SQL Support for MERGE INTO in Presto (engine) (削除ここまで) (追記) feat: Add SQL Support for MERGE INTO in Presto (engine) (追記ここまで) Oct 10, 2025
@acarpente-denodo acarpente-denodo force-pushed the feature/20578_SQL_Support_for_MERGE_INTO_(engine) branch from b8f9b3e to b27ac47 Compare October 13, 2025 12:21
@tdcmeehan tdcmeehan self-assigned this Oct 13, 2025
@acarpente-denodo acarpente-denodo force-pushed the feature/20578_SQL_Support_for_MERGE_INTO_(engine) branch 2 times, most recently from 71aebc7 to 6f60239 Compare October 14, 2025 08:00
Copy link
Contributor

Please include documentation for SQL MERGE INTO as a new file in
https://github.com/prestodb/presto/tree/master/presto-docs/src/main/sphinx/sql
and add the new file to the index page
https://github.com/prestodb/presto/blob/master/presto-docs/src/main/sphinx/sql.rst

@acarpente-denodo acarpente-denodo force-pushed the feature/20578_SQL_Support_for_MERGE_INTO_(engine) branch from 6f60239 to 7a54a60 Compare October 14, 2025 14:00
Copy link
Contributor Author

Hi @steveburnett. I appreciate your feedback. I added a new commit that includes the documentation for the MERGE INTO command.

steveburnett reacted with heart emoji

@acarpente-denodo acarpente-denodo force-pushed the feature/20578_SQL_Support_for_MERGE_INTO_(engine) branch from 7a54a60 to 8a860c1 Compare October 15, 2025 13:55
acarpente-denodo and others added 3 commits October 16, 2025 10:13
Working in progress
Cherry-pick of trinodb/trino@cee96c3
Co-authored-by: David Stryker <david.stryker@starburstdata.com>
Automated tests.
Cherry-pick of trinodb/trino@cee96c3
Co-authored-by: David Stryker <david.stryker@starburstdata.com>
@acarpente-denodo acarpente-denodo force-pushed the feature/20578_SQL_Support_for_MERGE_INTO_(engine) branch from 8a860c1 to 61ea3bd Compare October 16, 2025 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sourcery-ai sourcery-ai[bot] sourcery-ai[bot] left review comments

@steveburnett steveburnett Awaiting requested review from steveburnett steveburnett will be requested when the pull request is marked ready for review steveburnett is a code owner

@elharo elharo Awaiting requested review from elharo elharo will be requested when the pull request is marked ready for review elharo is a code owner

@jaystarshot jaystarshot Awaiting requested review from jaystarshot jaystarshot will be requested when the pull request is marked ready for review jaystarshot is a code owner

@feilong-liu feilong-liu Awaiting requested review from feilong-liu feilong-liu will be requested when the pull request is marked ready for review feilong-liu is a code owner

@ClarenceThreepwood ClarenceThreepwood Awaiting requested review from ClarenceThreepwood ClarenceThreepwood will be requested when the pull request is marked ready for review ClarenceThreepwood is a code owner

At least 1 approving review is required to merge this pull request.

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /