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
[SPARK-19335][SPARK-38200][SQL] Add upserts for writing to JDBC using MERGE INTO with temp table #41611
Open
EnricoMi
wants to merge
16
commits into
apache:master
Choose a base branch
from
G-Research:jdbc-upsert-merge-temp-table
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+679
−36
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
from
June 15, 2023 09:39
7a0e4d2
to
9cc6b39
Compare
EnricoMi
changed the title
[SPARK-38200][SQL] JDBC upsert MERGE INTO using temp table
[SPARK-38200][SQL] Add upserts for writing to JDBC using MERGE INTO with temp table
Jun 15, 2023
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
3 times, most recently
from
June 16, 2023 06:57
1ade6b4
to
76d0429
Compare
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
from
June 23, 2023 10:23
76d0429
to
0439e5d
Compare
EnricoMi
changed the title
[SPARK-38200][SQL] Add upserts for writing to JDBC using MERGE INTO with temp table
[SPARK-19335][SPARK-38200][SQL] Add upserts for writing to JDBC using MERGE INTO with temp table
Jun 23, 2023
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
from
June 30, 2023 09:34
95dc877
to
265dd1f
Compare
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
from
July 18, 2023 12:46
265dd1f
to
2c3faec
Compare
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
from
July 26, 2023 12:32
cdb889d
to
db2d78d
Compare
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
from
October 9, 2023 13:39
db2d78d
to
464a19a
Compare
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
2 times, most recently
from
October 26, 2023 10:21
7658bbc
to
80a2a9c
Compare
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
from
December 1, 2023 15:31
80a2a9c
to
d064da1
Compare
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
from
January 10, 2024 19:46
d064da1
to
5e69410
Compare
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
3 times, most recently
from
January 23, 2024 09:04
38ce6b9
to
60e41ca
Compare
Derby does not support indices on temp tables: https://db.apache.org/derby/docs/10.2/ref/rrefdeclaretemptable.html
EnricoMi
force-pushed
the
jdbc-upsert-merge-temp-table
branch
from
April 20, 2024 16:19
10fd22b
to
e3ade6e
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Implements upsert mode for
SaveMode.Append
of the MsSql, Postgres, Derby, H2 and oracle JDBC source.This uses
MERGE INTO
in combination with a temporary table. A batch of rows is inserted into the temporary table (rather than the target table) and merged into the target table with oneMERGE INTO
command per batch.See #41518 for an alternative for databases not supporting
MERGE INTO
syntax.Why are the changes needed?
The JDBC writer only supports either truncating the existing table or inserting. Duplicates, i.e. rows with identical values in the primary or unique index columns, cause an exception, permitting updating existing and inserting new rows.
Re-evaluating a partition due to executor loss will insert rows that have been inserted in an earlier attempt, which kills the entier Spark job.
Does this PR introduce any user-facing change?
This adds
upsert
andupsertKeyColumns
options forSaveMode.Append
of the JDBC source.How was this patch tested?
Tests in
JdbcSuite
and integration suites.