Skip to content

Commit f9a2fa0

Browse files
committed
Using the scale from logical schema instead of the number value.
1 parent c6116bd commit f9a2fa0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

oracle-plugin/src/main/java/io/cdap/plugin/oracle/OracleSourceDBRecord.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,23 @@ private void handleOracleSpecificType(ResultSet resultSet, StructuredRecord.Buil
214214
if (Double.class.getTypeName().equals(resultSet.getMetaData().getColumnClassName(columnIndex))) {
215215
recordBuilder.set(field.getName(), resultSet.getDouble(columnIndex));
216216
} else {
217-
// For a Number type without specified precision and scale, precision will be 0 and scale will be -127
218-
if (precision == 0) {
219-
// reference : https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832
220-
scale = 0;
221-
}
222217
// It's required to pass 'scale' parameter since in the case of Oracle, scale of 'BigDecimal' depends on the
223-
// scale of actual value. For example for value '77.12' scale will be '2' even if sql scale is '6'
224-
BigDecimal decimal = resultSet.getBigDecimal(columnIndex, scale);
218+
// scale set in the logical schema. For example for value '77.12' if the scale set in the logical schema is
219+
// set to 4 then the number will change to '77.1200'. Also if the value is '22.1274' and the logical schema
220+
// scale is set to 2 then the decimal value used will be '22.13' after rounding.
221+
BigDecimal decimal = resultSet.getBigDecimal(columnIndex, getSchemaScale(field.getSchema()));
225222
recordBuilder.setDecimal(field.getName(), decimal);
226223
}
227224
}
228225
}
229226

227+
/**
228+
* Get the schema scale set in Non-nullable schema associated with the schema
229+
* */
230+
private int getSchemaScale(Schema schema) {
231+
return schema.isNullable() ? schema.getNonNullable().getScale() : schema.getScale();
232+
}
233+
230234
private boolean isLongOrLongRaw(int columnType) {
231235
return columnType == OracleSourceSchemaReader.LONG || columnType == OracleSourceSchemaReader.LONG_RAW;
232236
}

0 commit comments

Comments
 (0)