{"record":{"id":"60e19b0bfdc9bd62","repo":"jd-opensource/joyagent-jdgenie","slug":"fieldname-value","errorCode":null,"errorMessage":"字段\" + fieldName + \"值\\\"\" + value + \"\\\"转换成数值失败","messagePattern":"字段\" \\+ fieldName \\+ \"值\\\\\"\" \\+ value \\+ \"\\\\\"转换成数值失败","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/data/jdbc/catalog/clickhouse/ClickhouseCatalog.java","lineNumber":57,"sourceCode":"    }\n\n\n    public String getColumnType(String columnType) {\n        return switch (StandardColumnType.of(columnType)) {\n            case DECIMAL -> \"Decimal64(4)\";\n            case DATE -> \"DateTime\";\n            default -> \"String\";\n        };\n    }\n\n\n    public BigDecimal parseDecimal(String value, String fieldName) {\n        BigDecimal decimal = null;\n        if (StringUtils.isNotBlank(value)) {\n            try {\n                decimal = new BigDecimal(value);\n            } catch (Exception e) {\n                throw new CatalogException(\"字段\" + fieldName + \"值\\\"\" + value + \"\\\"转换成数值失败\", e);\n            }\n        }\n        return decimal;\n    }\n}\n","sourceCodeStart":39,"sourceCodeEnd":63,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/data/jdbc/catalog/clickhouse/ClickhouseCatalog.java#L39-L63","documentation":"ClickhouseCatalog.parseDecimal converts a string column value to BigDecimal. If the value is non-blank but not a valid decimal number, it throws CatalogException '字段<fieldName>值\"<value>\"转换成数值失败'. This guards callers from silently receiving a null or malformed numeric value.","triggerScenarios":"Calling parseDecimal(value, fieldName) with a string like 'abc', '1.2.3', or a localized number with thousand separators that BigDecimal cannot parse.","commonSituations":"ClickHouse columns of type String/Enum that actually hold non-numeric data, values with spaces or currency symbols, or locale-formatted numbers (e.g. '1,234.56') coming from user input or CSV imports.","solutions":["Validate the value is a valid decimal (regex ^-?\\d+(\\.\\d+)?$) before calling parseDecimal.","Clean the value: strip separators/symbols and trim whitespace.","Change the source column to a numeric ClickHouse type so raw values are already numeric.","Catch CatalogException and treat the row as invalid data in your ETL."],"exampleFix":"// before\ncatalog.parseDecimal(\"1,234.56\", \"amount\"); // throws\n// after\nString cleaned = \"1,234.56\".replace(\",\", \"\").trim();\nBigDecimal v = catalog.parseDecimal(cleaned, \"amount\");","handlingStrategy":"validation","validationCode":"// Java: pre-validate the value parses as a decimal\nboolean isDecimal(String v) {\n    if (v == null || v.isBlank()) return true; // parseDecimal returns null for blank\n    return v.trim().matches(\"-?\\\\d+(\\\\.\\\\d+)?\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    BigDecimal d = catalog.parseDecimal(value, fieldName);\n} catch (CatalogException e) {\n    log.warn(\"Non-numeric value for {}: {}\", fieldName, value);\n    // treat row as invalid or apply default\n}","preventionTips":["Strip thousands separators and currency symbols before conversion.","Coerce source columns to numeric types at the ClickHouse level.","Trim whitespace before calling parseDecimal.","Decide a policy for blank values (parseDecimal returns null)."],"tags":["parsing","numeric","numberformatexception"],"backgroundTag":"invalid-argument-format","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}