{"record":{"id":"371d3946e60a5a03","repo":"apache/seatunnel","slug":"decimal-precision-d-exceeds-configured-precision","errorCode":null,"errorMessage":"Decimal precision %d exceeds configured precision %d","messagePattern":"Decimal precision (.+?) exceeds configured precision (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/serialize/DocumentDBItemDeserializer.java","lineNumber":169,"sourceCode":"            }\n            return value.asNumber().longValue();\n        }\n        throw new IllegalArgumentException(\"Value is not a supported long\");\n    }\n\n    /**\n     * Applies the configured scale and rejects precision overflow instead of silently emitting\n     * {@code null}, which would make malformed source data indistinguishable from BSON null.\n     */\n    private static BigDecimal convertDecimal(DecimalType type, BsonValue value) {\n        Decimal128 decimal128 = value.asDecimal128().decimal128Value();\n        if (!decimal128.isFinite()) {\n            throw new IllegalArgumentException(\"Infinite Decimal128 values are not supported\");\n        }\n        BigDecimal decimal =\n                decimal128.bigDecimalValue().setScale(type.getScale(), RoundingMode.HALF_UP);\n        if (decimal.precision() > type.getPrecision()) {\n            throw new IllegalArgumentException(\n                    String.format(\n                            \"Decimal precision %d exceeds configured precision %d\",\n                            decimal.precision(), type.getPrecision()));\n        }\n        return decimal;\n    }\n\n    private static String convertString(BsonValue value) {\n        if (value.isString()) {\n            return value.asString().getValue();\n        }\n        if (value.isObjectId()) {\n            return value.asObjectId().getValue().toHexString();\n        }\n        if (value.isDocument()) {\n            return value.asDocument().toJson(RELAXED_JSON_SETTINGS);\n        }\n        return value.toString();","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/serialize/DocumentDBItemDeserializer.java#L151-L187","documentation":"DocumentDBItemDeserializer.convertDecimal converts a BSON Decimal128 into a BigDecimal scaled to the configured SeaTunnel DecimalType. After scaling with HALF_UP rounding, if the resulting precision (total significant digits) still exceeds the configured precision, it throws this IllegalArgumentException. This guards that data written downstream matches the declared schema precision.","triggerScenarios":"Reading a DocumentDB document whose Decimal128 field has more significant digits than the precision declared for the corresponding DECIMAL column in the SeaTunnel schema (e.g. a Decimal128 with 20 digits against DECIMAL(10,2)), even after rounding the scale down.","commonSituations":"Source collection holds high-precision monetary or scientific values while the SeaTunnel schema was declared with a small DECIMAL(p,s); schema inferred from a sample that contained small values but production data has larger magnitudes (integer-digit overflow, which rounding cannot fix).","solutions":["Increase the precision of the DECIMAL type in the SeaTunnel schema so it covers the integer digits plus scale (precision >= integerDigits + scale).","Pre-clean or truncate the Decimal128 values in DocumentDB (e.g. aggregate pipeline with $trunc or $round) so they fit the configured precision.","Map the field to DOUBLE instead of DECIMAL if exact precision is not required.","Wrap the read in error handling that routes offending rows to a dead-letter path instead of failing the job."],"exampleFix":"// before: schema too narrow for the data\n DECIMAL(10,2)\n// after: widen precision to fit values up to 12 integer digits + 2 decimals\n DECIMAL(14,2)","handlingStrategy":"validation","validationCode":"BigDecimal scaled = decimal128.bigDecimalValue().setScale(targetScale, RoundingMode.HALF_UP);\nif (scaled.precision() > targetPrecision) {\n    throw new IllegalArgumentException(\"Value \" + scaled + \" exceeds DECIMAL(\" + targetPrecision + \",\" + targetScale + \")\");\n}","typeGuard":"boolean fitsDecimal(BigDecimal v, int precision) { return v.precision() <= precision; }","tryCatchPattern":"try { row = deserializer.convert(field, decimalType, bsonValue); } catch (IllegalArgumentException e) { log.warn(\"Decimal overflow for field {}: {}\", field, e.getMessage()); routeToDeadLetter(field, bsonValue); }","preventionTips":["Declare DECIMAL precision >= max integer digits + scale of your data; sample production documents, not just test data.","Validate a few hundred production documents against the schema before running the full job.","Use DOUBLE when exact decimal semantics are not required."],"tags":["java","documentdb","decimal","schema"],"backgroundTag":"value-out-of-range","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}