-
Notifications
You must be signed in to change notification settings - Fork 34
feat: Add MERGE (UPSERT) support to Oracle Sink #636
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
base: develop
Are you sure you want to change the base?
feat: Add MERGE (UPSERT) support to Oracle Sink #636
Conversation
This commit enhances the Oracle Sink plugin to support `MERGE` operations, providing an idempotent way to handle data writes, especially in scenarios involving Spark task retries. New Features: - **UPSERT Operation:** A new `operation` property in the sink configuration allows users to specify "upsert". - **Merge Keys:** A `mergeKeys` property is introduced to define the column(s) for the `MERGE` statement's `ON` clause. - **`OracleETLDBOutputFormat`:** A new class extending `ETLDBOutputFormat` to construct the Oracle-specific `MERGE` SQL statement using a `USING DUAL` approach. - **Conditional Logic:** The sink now conditionally uses `OracleETLDBOutputFormat` when the "upsert" operation is selected. Test Improvements: - Updated `docker-compose.yml` to use `container-registry.oracle.com/database/free:latest` with healthcheck. - README.md updated to reflect new Oracle image and Podman instructions. - Increased test timeout in `DatabasePluginTestBase`. - Added `testDBSinkUniqueConstraintViolation` to `OracleSinkTestRun` to demonstrate ORA-00001 on duplicate INSERTs. - Added `testDBSinkMerge` to `OracleSinkTestRun` to validate the new UPSERT functionality. - Commented out `apache-rat-plugin` in the root `pom.xml` to potentially speed up local builds. This change addresses issues where task retries could lead to unique constraint violations (ORA-00001) by providing a true upsert mechanism.
|
Internal notes: go/sf/64273740 |
| MySQL, Postgresql, MSSQL, DB2, MemSQL, SAP HANA, and Oracle are using prebuilt images. | ||
|
|
||
| Oracle DB image should be build separately. | ||
| MemSQL image should be configure after start. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these are added?
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to remove this
| } | ||
|
|
||
| @Override | ||
| protected void insertOperation(PreparedStatement stmt) throws SQLException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this method is removed?
| @@ -0,0 +1,63 @@ | |||
| import java.sql.Connection; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this relevant to plugin code
| super.test(JDBC_DRIVER_CLASS_NAME, connector, "Failed to create connection to database via connection string:" + | ||
| " jdbc:oracle:thin:@localhost:1521:database and arguments: " + | ||
| "{user=username, oracle.jdbc.timezoneAsRegion=false, " + | ||
| "{oracle.jdbc.timezoneAsRegion=false, user=username, " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why sequence is reversed
This commit enhances the Oracle Sink plugin to support
MERGEoperations, providing an idempotent way to handle data writes, especially in scenarios involving Spark task retries.New Features:
operationproperty in the sink configuration allows users to specify "upsert".mergeKeysproperty is introduced to define the column(s) for theMERGEstatement'sONclause.OracleETLDBOutputFormat: A new class extendingETLDBOutputFormatto construct the Oracle-specificMERGESQL statement using aUSING DUALapproach.OracleETLDBOutputFormatwhen the "upsert" operation is selected.Test Improvements:
docker-compose.ymlto usecontainer-registry.oracle.com/database/free:latestwith healthcheck.DatabasePluginTestBase.testDBSinkUniqueConstraintViolationtoOracleSinkTestRunto demonstrate ORA-00001 on duplicate INSERTs.testDBSinkMergetoOracleSinkTestRunto validate the new UPSERT functionality.apache-rat-pluginin the rootpom.xmlto potentially speed up local builds.This change addresses issues where task retries could lead to unique constraint violations (ORA-00001) by providing a true upsert mechanism.