Skip to content

Conversation

@psainics
Copy link
Contributor

@psainics psainics commented Apr 15, 2025

ErrorDetailsProvider - Mariadb [Source|Sink] plugin

Jira : PLUGIN-1885

Description

Implement Program Failure Exception Handling in Mariadb Source/Sink plugin to catch known errors

Code change

  • Added MariadbErrorDetailsProvider.java
  • Modified DBUtils.java
  • Modified MariadbSink.java
  • Modified MariadbSource.java

Tests

  • Sanity (file source to mariadb sink)

image

  • Test Case (Violate check constrain)

  • Table Used

-- Create the users table
CREATE TABLE users (
    name VARCHAR(100) NOT NULL,
    age INT NOT NULL,
    gender ENUM('male', 'female') NOT NULL,
    CHECK (gender IN ('male', 'female'))
);

-- Insert two records into the users table
INSERT INTO users (name, age, gender) VALUES ('John Doe', 30, 'male');
INSERT INTO users (name, age, gender) VALUES ('Jane Smith', 25, 'female');
Raw Logs
2025-04-15 17:59:02,041 - ERROR [Executor task launch worker for task 0.0 in stage 0.0 (TID 0):o.a.s.u.Utils@98] - Aborting task
io.cdap.cdap.api.exception.WrappedStageException: Stage 'MariaDB' encountered : io.cdap.cdap.api.exception.ProgramFailureException: Error occurred in the phase: 'Writing' with sqlState: '01000', errorCode: '1265', errorMessage: SQL Exception occurred: [Message='(conn=55) Data truncated for column 'gender' at row 1', SQLState='01000', ErrorCode='1265'].
  at io.cdap.cdap.etl.common.ErrorDetails.handleException(ErrorDetails.java:77)
  at io.cdap.cdap.etl.spark.io.StageTrackingRecordWriter.close(StageTrackingRecordWriter.java:67)
  at org.apache.spark.internal.io.HadoopMapReduceWriteConfigUtil.closeWriter(SparkHadoopWriter.scala:373)
  at org.apache.spark.internal.io.SparkHadoopWriter$.$anonfun$executeTask$1(SparkHadoopWriter.scala:145)
  at org.apache.spark.util.Utils$.tryWithSafeFinallyAndFailureCallbacks(Utils.scala:1538)
  at org.apache.spark.internal.io.SparkHadoopWriter$.executeTask(SparkHadoopWriter.scala:135)
  at org.apache.spark.internal.io.SparkHadoopWriter$.$anonfun$write$1(SparkHadoopWriter.scala:88)
  at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
  at org.apache.spark.scheduler.Task.run(Task.scala:136)
  at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:548)
  at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1504)
  at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:551)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  at java.lang.Thread.run(Thread.java:750)
Caused by: io.cdap.cdap.api.exception.ProgramFailureException: Error occurred in the phase: 'Writing' with sqlState: '01000', errorCode: '1265', errorMessage: SQL Exception occurred: [Message='(conn=55) Data truncated for column 'gender' at row 1', SQLState='01000', ErrorCode='1265'].
  at io.cdap.cdap.api.exception.ProgramFailureException$Builder.build(ProgramFailureException.java:229)
  at io.cdap.cdap.api.exception.ErrorUtils.getProgramFailureException(ErrorUtils.java:198)
  at io.cdap.plugin.common.db.DBErrorDetailsProvider.getProgramFailureException(DBErrorDetailsProvider.java:202)
  at io.cdap.plugin.common.db.DBErrorDetailsProvider.getExceptionDetails(DBErrorDetailsProvider.java:172)
  at io.cdap.cdap.etl.common.ErrorDetails.handleException(ErrorDetails.java:75)
  ... 14 common frames omitted
Caused by: java.sql.BatchUpdateException: (conn=55) Data truncated for column 'gender' at row 1
  at org.mariadb.jdbc.export.ExceptionFactory.createBatchUpdate(ExceptionFactory.java:181)
  at org.mariadb.jdbc.BasePreparedStatement.executeBatchBulk(BasePreparedStatement.java:1956)
  at org.mariadb.jdbc.ClientPreparedStatement.executeInternalPreparedBatch(ClientPreparedStatement.java:137)
  at org.mariadb.jdbc.BasePreparedStatement.executeBatchInternal(BasePreparedStatement.java:1694)
  at org.mariadb.jdbc.BasePreparedStatement.executeBatch(BasePreparedStatement.java:1680)
  at io.cdap.plugin.db.sink.ETLDBOutputFormat$1.close(ETLDBOutputFormat.java:99)
  at io.cdap.cdap.etl.spark.io.TrackingRecordWriter.close(TrackingRecordWriter.java:46)
  at io.cdap.cdap.etl.spark.io.StageTrackingRecordWriter.close(StageTrackingRecordWriter.java:65)
  ... 13 common frames omitted
Caused by: java.sql.BatchUpdateException: (conn=55) Data truncated for column 'gender' at row 1
  at org.mariadb.jdbc.export.ExceptionFactory.createBatchUpdate(ExceptionFactory.java:221)
  at org.mariadb.jdbc.client.impl.StandardClient.executePipeline(StandardClient.java:1129)
  at org.mariadb.jdbc.BasePreparedStatement.executeBatchBulk(BasePreparedStatement.java:1923)
  ... 19 common frames omitted
Caused by: java.sql.SQLTransientConnectionException: (conn=55) Data truncated for column 'gender' at row 1
  at org.mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:309)
  at org.mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:378)
  at org.mariadb.jdbc.message.ClientMessage.readPacket(ClientMessage.java:187)
  at org.mariadb.jdbc.client.impl.StandardClient.readPacket(StandardClient.java:1364)
  at org.mariadb.jdbc.client.impl.StandardClient.readResults(StandardClient.java:1303)
  at org.mariadb.jdbc.client.impl.StandardClient.readResponse(StandardClient.java:1222)
  at org.mariadb.jdbc.client.impl.StandardClient.executePipeline(StandardClient.java:1062)
  ... 20 common frames omitted
2025-04-15 17:59:02,043 - WARN  [Executor task launch worker for task 0.0 in stage 0.0 (TID 0):i.c.p.d.s.ETLDBOutputFormat@106] - java.sql.SQLNonTransientConnectionException: (conn=55) Connection is closed
  at org.mariadb.jdbc.export.ExceptionFactory.createException(ExceptionFactory.java:300)
  at org.mariadb.jdbc.export.ExceptionFactory.create(ExceptionFactory.java:378)
  at org.mariadb.jdbc.Connection.checkNotClosed(Connection.java:700)
  at org.mariadb.jdbc.Connection.rollback(Connection.java:234)
  at io.cdap.plugin.db.sink.ETLDBOutputFormat$1.close(ETLDBOutputFormat.java:104)
  at io.cdap.cdap.etl.spark.io.TrackingRecordWriter.close(TrackingRecordWriter.java:46)
  at io.cdap.cdap.etl.spark.io.StageTrackingRecordWriter.close(StageTrackingRecordWriter.java:65)
  at org.apache.spark.internal.io.HadoopMapReduceWriteConfigUtil.closeWriter(SparkHadoopWriter.scala:373)
  at org.apache.spark.internal.io.SparkHadoopWriter$.$anonfun$executeTask$2(SparkHadoopWriter.scala:150)
  at org.apache.spark.util.Utils$.tryWithSafeFinallyAndFailureCallbacks(Utils.scala:1549)
  at org.apache.spark.internal.io.SparkHadoopWriter$.executeTask(SparkHadoopWriter.scala:135)
  at org.apache.spark.internal.io.SparkHadoopWriter$.$anonfun$write$1(SparkHadoopWriter.scala:88)
  at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
  at org.apache.spark.scheduler.Task.run(Task.scala:136)
  at org.apache.spark.executor.Executor$TaskRunner.$anonfun$run$3(Executor.scala:548)
  at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1504)
  at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:551)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  at java.lang.Thread.run(Thread.java:750)

POST v3/namespaces/{namespace-id}/apps/{app-id}/workflows/DataPipelineWorkflow/runs/{run-id}/classify
[
{
  "stageName": "MariaDB",
  "errorCategory": "Plugin-'DB Warning'-'MariaDB'",
  "errorReason": "SQL Exception occurred: [Message='(conn=55) Data truncated for column 'gender' at row 1', SQLState='01000', ErrorCode='1265']. For more details, see https://mariadb.com/kb/en/mariadb-error-codes/",
  "errorMessage": "Error occurred in the phase: 'Writing' with sqlState: '01000', errorCode: '1265', errorMessage: SQL Exception occurred: [Message='(conn=55) Data truncated for column 'gender' at row 1', SQLState='01000', ErrorCode='1265'].",
  "errorType": "USER",
  "dependency": "true",
  "errorCodeType": "SQLSTATE",
  "errorCode": "01000",
  "supportedDocumentationUrl": "https://mariadb.com/kb/en/mariadb-error-codes/"
}
]

image

@psainics psainics added the build label Apr 15, 2025
@psainics psainics self-assigned this Apr 15, 2025
@psainics psainics merged commit cde7167 into data-integrations:develop Apr 16, 2025
17 checks passed
@psainics psainics deleted the fem/Mariadb branch April 16, 2025 08:34
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.

2 participants