Skip to content

Commit

Permalink
numeric_precision_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubhangi-cs committed Sep 12, 2023
1 parent 3e9fbf9 commit 1f3f735
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void write(PreparedStatement stmt) throws SQLException {
}
}

private Schema getNonNullableSchema(Schema.Field field) {
protected Schema getNonNullableSchema(Schema.Field field) {
Schema schema = field.getSchema();
if (field.getSchema().isNullable()) {
schema = field.getSchema().getNonNullable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private Object createPGobject(String type, String value, ClassLoader classLoader
protected void writeToDB(PreparedStatement stmt, Schema.Field field, int fieldIndex) throws SQLException {
int sqlIndex = fieldIndex + 1;
ColumnType columnType = columnTypes.get(fieldIndex);
Schema fieldSchema = getNonNullableSchema(field);
if (PostgresSchemaReader.STRING_MAPPED_POSTGRES_TYPES_NAMES.contains(columnType.getTypeName()) ||
PostgresSchemaReader.STRING_MAPPED_POSTGRES_TYPES.contains(columnType.getType())) {
stmt.setObject(sqlIndex, createPGobject(columnType.getTypeName(),
Expand All @@ -114,7 +115,7 @@ protected void writeToDB(PreparedStatement stmt, Schema.Field field, int fieldIn
return;
}
if (columnType.getType() == Types.NUMERIC && record.get(field.getName()) != null &&
field.getSchema().getType() == Schema.Type.STRING) {
fieldSchema.getType() == Schema.Type.STRING) {
stmt.setBigDecimal(sqlIndex, new BigDecimal((String) record.get(field.getName())));
return;
}
Expand Down

0 comments on commit 1f3f735

Please sign in to comment.