|
24 | 24 | import io.cdap.plugin.db.ColumnType; |
25 | 25 | import io.cdap.plugin.db.DBRecord; |
26 | 26 | import io.cdap.plugin.db.SchemaReader; |
| 27 | +import org.slf4j.Logger; |
| 28 | +import org.slf4j.LoggerFactory; |
27 | 29 |
|
28 | 30 | import java.io.IOException; |
29 | 31 | import java.io.InputStream; |
|
48 | 50 | */ |
49 | 51 | public class OracleSourceDBRecord extends DBRecord { |
50 | 52 |
|
| 53 | + private static final Logger LOG = LoggerFactory.getLogger(OracleSourceDBRecord.class); |
| 54 | + |
51 | 55 | public OracleSourceDBRecord(StructuredRecord record, List<ColumnType> columnTypes) { |
52 | 56 | this.record = record; |
53 | 57 | this.columnTypes = columnTypes; |
@@ -214,16 +218,31 @@ private void handleOracleSpecificType(ResultSet resultSet, StructuredRecord.Buil |
214 | 218 | if (Double.class.getTypeName().equals(resultSet.getMetaData().getColumnClassName(columnIndex))) { |
215 | 219 | recordBuilder.set(field.getName(), resultSet.getDouble(columnIndex)); |
216 | 220 | } else { |
| 221 | + int scaleInSchema = getScale(field.getSchema()); |
| 222 | + if (precision == 0 && scaleInSchema == 0) { |
| 223 | + BigDecimal value = BigDecimal.valueOf(resultSet.getDouble(columnIndex)); |
| 224 | + if (value != null && !containsIntegerValue(value)) { |
| 225 | + LOG.warn(String.format("Precision loss detected in the field '%s'. " |
| 226 | + + "Scale in the data='%s' scale present in the schema='%s'.", |
| 227 | + field.getName(), |
| 228 | + value.scale(), |
| 229 | + scaleInSchema)); |
| 230 | + } |
| 231 | + } |
217 | 232 | // It's required to pass 'scale' parameter since in the case of Oracle, scale of 'BigDecimal' depends on the |
218 | 233 | // scale set in the logical schema. For example for value '77.12' if the scale set in the logical schema is |
219 | 234 | // set to 4 then the number will change to '77.1200'. Also if the value is '22.1274' and the logical schema |
220 | 235 | // scale is set to 2 then the decimal value used will be '22.13' after rounding. |
221 | | - BigDecimal decimal = resultSet.getBigDecimal(columnIndex, getScale(field.getSchema())); |
| 236 | + BigDecimal decimal = resultSet.getBigDecimal(columnIndex, scaleInSchema); |
222 | 237 | recordBuilder.setDecimal(field.getName(), decimal); |
223 | 238 | } |
224 | 239 | } |
225 | 240 | } |
226 | 241 |
|
| 242 | + private boolean containsIntegerValue(BigDecimal value) { |
| 243 | + return value.remainder(BigDecimal.ONE).compareTo(BigDecimal.ZERO) == 0; |
| 244 | + } |
| 245 | + |
227 | 246 | /** |
228 | 247 | * Get the scale set in Non-nullable schema associated with the schema |
229 | 248 | * */ |
|
0 commit comments