close
Skip to content

[Fix][Connector-jdbc] Fix postgresql sink trying to update unique key (#9293)#9298

Merged
hailin0 merged 1 commit into
apache:devfrom
papadave66:fix-pg-update-primary-key
May 16, 2025
Merged

[Fix][Connector-jdbc] Fix postgresql sink trying to update unique key (#9293)#9298
hailin0 merged 1 commit into
apache:devfrom
papadave66:fix-pg-update-primary-key

Conversation

@papadave66

@papadave66 papadave66 commented May 9, 2025

Copy link
Copy Markdown
Contributor

Purpose of this pull request

close #9293

The JDBC connector of postgresql trying to update primary key colums which is not needed. Then I do some research on apache/flink-connector-jdbc#155 . They fix this month ago. So I think fix in here should be a good idea :)
And I use [fix] instead of [bug] because I am not sure if it is a bug or a feature.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Unit test: org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.psql.PostgresDialectTest

Check list

@papadave66 papadave66 changed the title [fix][connector-jdbc] fix postgresql update primary key (#9293) [fix][connector-jdbc] fix postgresql sink trying to update primary key (#9293) May 9, 2025
@papadave66 papadave66 force-pushed the fix-pg-update-primary-key branch from 7c8020e to 110157d Compare May 9, 2025 08:37
@nielifeng nielifeng requested a review from Copilot May 9, 2025 09:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes an issue in the PostgreSQL JDBC connector where primary key columns were unnecessarily updated during upsert operations. The diff updates the dialect logic to conditionally generate either a DO NOTHING or a DO UPDATE clause based on the provided key fields and adds accompanying tests as well as an entry in the release note.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresDialectTest.java Added unit tests verifying correct upsert statement generation
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresDialect.java Adjusted upsert statement logic to filter out primary key fields during update clause construction
release-note.md Updated release note to reflect the fix
Comments suppressed due to low confidence (2)

seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresDialectTest.java:32

  • [nitpick] Consider renaming 'doUpdatekeyFields' to 'doUpdateKeyFields' to follow standard camelCase naming conventions.
final String[] doUpdatekeyFields = {"id"};

seatunnel-connectors-v2/connector-jdbc/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresDialectTest.java:33

  • [nitpick] Consider renaming 'doNothingkeyFields' to 'doNothingKeyFields' to follow standard camelCase naming conventions.
final String[] doNothingkeyFields = {"id", "type", "role_name", "description", "create_time", "update_time"};

@papadave66 papadave66 force-pushed the fix-pg-update-primary-key branch from 110157d to dd5b6dc Compare May 9, 2025 13:20
"id", "type", "role_name", "description", "create_time", "update_time"
};
final String[] doUpdateKeyFields = {"id"};
final String[] doNothingKeyFields = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed to camelCase style.

@Hisoka-X

Copy link
Copy Markdown
Member

Thanks @papadave66 ! LGTM. Please open ci on your fork repository. https://github.com/apache/seatunnel/pull/9298/checks?check_run_id=41943176159

@papadave66 papadave66 force-pushed the fix-pg-update-primary-key branch from 185c986 to 635f713 Compare May 13, 2025 00:26
@papadave66

Copy link
Copy Markdown
Contributor Author

Thanks @papadave66 ! LGTM. Please open ci on your fork repository. https://github.com/apache/seatunnel/pull/9298/checks?check_run_id=41943176159

Oh I just enabled the flow. Please tell me if i am doing correctly.

@Hisoka-X

Copy link
Copy Markdown
Member

Please resolve the conflicts.

@papadave66 papadave66 force-pushed the fix-pg-update-primary-key branch from 635f713 to e7314ad Compare May 13, 2025 04:25
@Hisoka-X

Copy link
Copy Markdown
Member

wating ci passes.

@papadave66 papadave66 force-pushed the fix-pg-update-primary-key branch from e7314ad to 996299c Compare May 13, 2025 11:44
@papadave66 papadave66 changed the title [fix][connector-jdbc] fix postgresql sink trying to update primary key (#9293) [Fix][connector-jdbc] fix postgresql sink trying to update primary key (#9293) May 15, 2025
@Hisoka-X Hisoka-X changed the title [Fix][connector-jdbc] fix postgresql sink trying to update primary key (#9293) [Fix][Connector-jdbc] Fix postgresql sink trying to update unique key (#9293) May 15, 2025
@hailin0 hailin0 merged commit d0c1de8 into apache:dev May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [Connector-V2] sink trying to update primary key in distribute sink database

4 participants