Skip to content

Conversation

@cjac
Copy link

@cjac cjac commented Nov 22, 2025

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.

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.
@cjac cjac marked this pull request as draft November 27, 2025 04:51
@cjac
Copy link
Author

cjac commented Nov 27, 2025

Internal notes:

go/sf/64273740
b/458793088

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.
Copy link
Contributor

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.
*/

Copy link
Contributor

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 {
Copy link
Contributor

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;
Copy link
Contributor

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, " +
Copy link
Contributor

Choose a reason for hiding this comment

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

why sequence is reversed

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.

2 participants