Skip to content

Commit 874c140

Browse files
refactored the query because postgress automatically converts unquoted column names to lowercase
1 parent a356d6b commit 874c140

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,20 @@ private void validateSchema(FailureCollector collector, Class<? extends Driver>
305305
return;
306306
}
307307
}
308-
309-
try (PreparedStatement pStmt = connection.prepareStatement("SELECT * FROM " + dbSinkConfig.getEscapedTableName()
310-
+ " WHERE 1 = 0");
308+
setColumnsInfo(inputSchema.getFields());
309+
try (PreparedStatement pStmt = connection.prepareStatement(String.format("SELECT %s FROM %s WHERE 1 = 0",
310+
dbColumns,
311+
dbSinkConfig.getEscapedTableName()));
311312
ResultSet rs = pStmt.executeQuery()) {
312313
getFieldsValidator().validateFields(inputSchema, rs, collector);
313314
}
314315
} catch (SQLException e) {
315316
LOG.error("Exception while trying to validate schema of database table {} for connection {}.",
316317
tableName, connectionString, e);
317318
collector.addFailure(
318-
String.format("Exception while trying to validate schema of database table '%s' for connection '%s'.",
319-
tableName, connectionString), null).withStacktrace(e.getStackTrace());
319+
String.format("Exception while trying to validate schema of database table '%s' for connection '%s' with %s",
320+
tableName, connectionString, e.getMessage()),
321+
null).withStacktrace(e.getStackTrace());
320322
}
321323
}
322324

0 commit comments

Comments
 (0)