From 1f3f735dd43e9466ec37b0cfde188d2346e0548e Mon Sep 17 00:00:00 2001 From: Shubhangi-cs Date: Tue, 12 Sep 2023 12:39:52 +0530 Subject: [PATCH] numeric_precision_fix --- database-commons/src/main/java/io/cdap/plugin/db/DBRecord.java | 2 +- .../main/java/io/cdap/plugin/postgres/PostgresDBRecord.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/database-commons/src/main/java/io/cdap/plugin/db/DBRecord.java b/database-commons/src/main/java/io/cdap/plugin/db/DBRecord.java index 7592a5fdf..f4c021ecf 100644 --- a/database-commons/src/main/java/io/cdap/plugin/db/DBRecord.java +++ b/database-commons/src/main/java/io/cdap/plugin/db/DBRecord.java @@ -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(); diff --git a/postgresql-plugin/src/main/java/io/cdap/plugin/postgres/PostgresDBRecord.java b/postgresql-plugin/src/main/java/io/cdap/plugin/postgres/PostgresDBRecord.java index 629eefad5..48ee35909 100644 --- a/postgresql-plugin/src/main/java/io/cdap/plugin/postgres/PostgresDBRecord.java +++ b/postgresql-plugin/src/main/java/io/cdap/plugin/postgres/PostgresDBRecord.java @@ -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(), @@ -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; }