{"record":{"id":"b9afc80ad9156f42","repo":"apache/seatunnel","slug":"cannot-convert-to-bigdecimal","errorCode":null,"errorMessage":"Cannot convert to BigDecimal: ","messagePattern":"Cannot convert to BigDecimal: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-iceberg/src/main/java/org/apache/seatunnel/connectors/seatunnel/iceberg/data/RowConverter.java","lineNumber":334,"sourceCode":"                \"Cannot convert to double: \" + value.getClass().getName());\n    }\n\n    protected BigDecimal convertDecimal(Object value, Types.DecimalType type) {\n        BigDecimal bigDecimal;\n        if (value instanceof BigDecimal) {\n            bigDecimal = (BigDecimal) value;\n        } else if (value instanceof Number) {\n            Number num = (Number) value;\n            Double dbl = num.doubleValue();\n            if (dbl.equals(Math.floor(dbl))) {\n                bigDecimal = BigDecimal.valueOf(num.longValue());\n            } else {\n                bigDecimal = BigDecimal.valueOf(dbl);\n            }\n        } else if (value instanceof String) {\n            bigDecimal = new BigDecimal((String) value);\n        } else {\n            throw new IllegalArgumentException(\n                    \"Cannot convert to BigDecimal: \" + value.getClass().getName());\n        }\n        return bigDecimal.setScale(type.scale(), RoundingMode.HALF_UP);\n    }\n\n    protected boolean convertBoolean(Object value) {\n        if (value instanceof Boolean) {\n            return (boolean) value;\n        } else if (value instanceof String) {\n            return Boolean.parseBoolean((String) value);\n        }\n        throw new IllegalArgumentException(\n                \"Cannot convert to boolean: \" + value.getClass().getName());\n    }\n\n    protected String convertString(Object value) {\n        try {\n            if (value instanceof String) {","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-iceberg/src/main/java/org/apache/seatunnel/connectors/seatunnel/iceberg/data/RowConverter.java#L316-L352","documentation":"Iceberg RowConverter throws this when a field value cannot be converted to the target decimal type. It accepts Number (double) and String inputs; anything else reaches the else branch. The class name of the offending value is appended to the message to help identify the source of the bad data.","triggerScenarios":"convertDecimal receives a value that is neither Number nor String while mapping a SeaTunnel row to an Iceberg DECIMAL column, e.g. a Boolean, byte[], or a null-typed boxed object produced upstream.","commonSituations":"Upstream source emits decimal columns as an unexpected Java type (e.g. CDC deserialization yields byte[] or BigDecimal handled by a different branch); schema mismatch where a string-typed SeaTunnel column maps to a decimal Iceberg column but a nested type slips through.","solutions":["Inspect the class name in the message and trace which upstream column produced that type.","Ensure the SeaTunnel source emits Number or String for decimal fields; configure source type mapping accordingly.","Add a transform to cast the column (e.g. CAST to DECIMAL) before the Iceberg sink.","If the value is genuinely non-numeric, fix data quality at the source or drop/coerce the field."],"exampleFix":"// before\nObject v = rowData.getField(2); // byte[] from upstream\n// after\nObject v = new String((byte[]) rowData.getField(2)); // or CAST in a transform so converter gets Number/String","handlingStrategy":"type-guard","validationCode":"if (!(v instanceof Number) && !(v instanceof String)) throw new IllegalArgumentException(\"decimal column must be Number/String, got \" + (v == null ? \"null\" : v.getClass().getName()));","typeGuard":"boolean isDecimalConvertible(Object v) { return v instanceof Number || v instanceof String; }","tryCatchPattern":"try { sink.write(row); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Cannot convert to BigDecimal\")) { log.error(\"Bad decimal value: {}\", e.getMessage()); /* skip or DLQ row */ } else throw e; }","preventionTips":["Map source decimal columns to SeaTunnel DecimalType or StringType","CAST non-numeric columns in a transform before the Iceberg sink","Log field classes during initial schema validation of new pipelines"],"tags":["iceberg","type-conversion","decimal","sink"],"backgroundTag":"type-mismatch","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}