wombatu-kun commented on code in PR #16606:
URL: https://github.com/apache/iceberg/pull/16606#discussion_r3691324488


##########
kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/SchemaUtils.java:
##########
@@ -306,7 +306,15 @@ Type inferIcebergType(Object value) {
         return BooleanType.get();
       } else if (value instanceof BigDecimal) {
         BigDecimal bigDecimal = (BigDecimal) value;
-        return DecimalType.of(bigDecimal.precision(), bigDecimal.scale());
+        int scale = bigDecimal.scale();
+        int precision = bigDecimal.precision();
+        // BigDecimal may use a negative scale (e.g. "1E+2" has scale -2)
+        if (scale < 0) {
+          precision -= scale;
+          scale = 0;
+        }
+        // a value < 1 may have precision < scale (e.g. "0.001"); widen 
precision to the scale
+        return DecimalType.of(Math.max(precision, scale), scale);

Review Comment:
   Done e081d1513. Out-of-range returns `null` rather than a capped type: 
`null` is this method's existing "cannot infer" signal, already returned for 
empty lists, empty maps and unrecognized classes, so `RecordConverter` skips 
the column and `autoCreateTable` raises a `DataException` instead of an 
`IllegalArgumentException` escaping inference. Clamping to `decimal(38, scale)` 
would silently drop significant digits. Boundaries are covered in 
`testInferIcebergTypeDecimalOutOfRange`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to