Skip to content

Commit a2bd3a9

Browse files
committed
PLUGIN-1823: Revert SQLException handling changes for validateSchema
1 parent 037a0d4 commit a2bd3a9

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

database-commons/src/main/java/io/cdap/plugin/db/sink/AbstractDBSink.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import io.cdap.plugin.common.ReferenceBatchSink;
4040
import io.cdap.plugin.common.ReferencePluginConfig;
4141
import io.cdap.plugin.common.batch.sink.SinkOutputFormatProvider;
42-
import io.cdap.plugin.common.util.ExceptionUtils;
4342
import io.cdap.plugin.db.ColumnType;
4443
import io.cdap.plugin.db.CommonSchemaReader;
4544
import io.cdap.plugin.db.ConnectionConfig;
@@ -59,7 +58,6 @@
5958
import org.slf4j.Logger;
6059
import org.slf4j.LoggerFactory;
6160

62-
import java.io.IOException;
6361
import java.sql.Connection;
6462
import java.sql.Driver;
6563
import java.sql.PreparedStatement;
@@ -129,17 +127,8 @@ public void configurePipeline(PipelineConfigurer pipelineConfigurer) {
129127
Class<? extends Driver> driverClass = DBUtils.getDriverClass(
130128
pipelineConfigurer, dbSinkConfig, ConnectionConfig.JDBC_PLUGIN_TYPE);
131129
if (driverClass != null && dbSinkConfig.canConnect()) {
132-
try {
133130
validateSchema(collector, driverClass, dbSinkConfig.getTableName(), inputSchema,
134131
dbSinkConfig.getDBSchemaName());
135-
} catch (SQLException e) {
136-
String details = String.format("SQL error while validating the schema: Error: %s, SQLState: %s, ErrorCode: %s",
137-
e.getMessage(), e.getSQLState(), e.getErrorCode());
138-
collector.addFailure(details,
139-
"Ensure the table exists and the connection string points to a valid database.")
140-
.withConfigProperty(DBSinkConfig.TABLE_NAME)
141-
.withStacktrace(e.getStackTrace());
142-
}
143132
}
144133
}
145134
public void validateOperations(FailureCollector collector, T dbSinkConfig, @Nullable Schema inputSchema) {
@@ -229,9 +218,6 @@ public void prepareRun(BatchSinkContext context) {
229218
} else {
230219
outputSchema = inferSchema(driverClass);
231220
}
232-
} catch (SQLException e) {
233-
throw new RuntimeException(String.format("Unable to validate schema due to: %s.",
234-
ExceptionUtils.getRootCauseMessage(e)), e);
235221
} finally {
236222
DBUtils.cleanup(driverClass);
237223
}
@@ -423,7 +409,7 @@ static List<ColumnType> getMatchedColumnTypeList(ResultSet resultSet, List<Strin
423409
}
424410

425411
private void validateSchema(FailureCollector collector, Class<? extends Driver> jdbcDriverClass, String tableName,
426-
Schema inputSchema, String dbSchemaName) throws SQLException {
412+
Schema inputSchema, String dbSchemaName) {
427413
String connectionString = dbSinkConfig.getConnectionString();
428414
String fullyQualifiedTableName = dbSchemaName == null ? dbSinkConfig.getEscapedTableName()
429415
: dbSinkConfig.getEscapedDbSchemaName() + "." + dbSinkConfig.getEscapedTableName();
@@ -459,6 +445,13 @@ connectionString, connectionProperties, getExternalDocumentationLink())) {
459445
getExternalDocumentationLink())) {
460446
getFieldsValidator().validateFields(inputSchema, rs, collector);
461447
}
448+
} catch (SQLException e) {
449+
LOG.error("Exception while trying to validate schema of database table {} for connection {}.",
450+
fullyQualifiedTableName, connectionString, e);
451+
collector.addFailure(
452+
String.format("Exception while trying to validate schema of database table '%s' for connection '%s' with %s",
453+
fullyQualifiedTableName, connectionString, e.getMessage()),
454+
null).withStacktrace(e.getStackTrace());
462455
}
463456
}
464457

0 commit comments

Comments
 (0)