From 80e71068bec6a665486d1264bb582ed94bd84bd3 Mon Sep 17 00:00:00 2001 From: Tamas Neumer Date: Mon, 31 Jul 2023 05:12:23 +0200 Subject: [PATCH] NIFI-11860 fixed bug in ResultSetRecordSet affecting decimalScale when resultSetScale was zero. Signed-off-by: Matt Burgess This closes #7545 --- .../serialization/record/ResultSetRecordSet.java | 2 +- .../record/ResultSetRecordSetTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/ResultSetRecordSet.java b/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/ResultSetRecordSet.java index 84a7b4569a..3357b06a7f 100644 --- a/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/ResultSetRecordSet.java +++ b/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/ResultSetRecordSet.java @@ -325,7 +325,7 @@ public class ResultSetRecordSet implements RecordSet, Closeable { decimalPrecision = resultSetPrecision; //For the float data type Oracle return decimalScale < 0 which cause is not expected to org.apache.avro.LogicalTypes //Hence falling back to default scale if decimalScale < 0 - decimalScale = resultSetScale > 0 ? resultSetScale : defaultScale; + decimalScale = resultSetScale >= 0 ? resultSetScale : defaultScale; } else { // If not, use default precision. decimalPrecision = defaultPrecision; diff --git a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/ResultSetRecordSetTest.java b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/ResultSetRecordSetTest.java index e9e5ec861b..b1c272cdf6 100644 --- a/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/ResultSetRecordSetTest.java +++ b/nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/record/ResultSetRecordSetTest.java @@ -130,6 +130,20 @@ public class ResultSetRecordSetTest { thenAllColumnDataTypesAreCorrect(COLUMNS, expectedSchema, actualSchema); } + @Test + public void testCreateSchemaWhenScaleIsNonDefault() throws SQLException { + // given + final RecordSchema recordSchema = givenRecordSchema(COLUMNS); + final RecordSchema expectedSchema = givenRecordSchema(COLUMNS); + + // when + final ResultSetRecordSet testSubject = new ResultSetRecordSet(resultSet, recordSchema, 10, 2); + final RecordSchema actualSchema = testSubject.getSchema(); + + // then + thenAllColumnDataTypesAreCorrect(COLUMNS, expectedSchema, actualSchema); + } + @Test public void testCreateSchemaWhenNoRecordSchema() throws SQLException { // given