{"record":{"id":"0b2a549e8eaa2b1d","repo":"apache/beam","slug":"conversion-from-s-to-bigdecimal-is-not-supported","errorCode":null,"errorMessage":"Conversion from %s to BigDecimal is not supported","messagePattern":"Conversion from (.+?) to BigDecimal is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/utils/BigDecimalConverter.java","lineNumber":46,"sourceCode":" * TypeName}.\n */\npublic class BigDecimalConverter {\n\n  private static final Map<TypeName, SerializableFunction<BigDecimal, ? extends Number>>\n      CONVERTER_MAP =\n          ImmutableMap.<TypeName, SerializableFunction<BigDecimal, ? extends Number>>builder()\n              .put(TypeName.INT32, BigDecimal::intValue)\n              .put(TypeName.INT16, BigDecimal::shortValue)\n              .put(TypeName.BYTE, BigDecimal::byteValue)\n              .put(TypeName.INT64, BigDecimal::longValue)\n              .put(TypeName.FLOAT, BigDecimal::floatValue)\n              .put(TypeName.DOUBLE, BigDecimal::doubleValue)\n              .put(TypeName.DECIMAL, v -> v)\n              .build();\n\n  public static SerializableFunction<BigDecimal, ? extends Number> forSqlType(TypeName typeName) {\n    if (!CONVERTER_MAP.containsKey(typeName)) {\n      throw new UnsupportedOperationException(\n          \"Conversion from \" + typeName + \" to BigDecimal is not supported\");\n    }\n\n    return CONVERTER_MAP.get(typeName);\n  }\n}\n","sourceCodeStart":28,"sourceCodeEnd":53,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/utils/BigDecimalConverter.java#L28-L53","documentation":"BigDecimalConverter.forSqlType looks up a BigDecimal -> Number conversion function in CONVERTER_MAP (INTEGER/BIGINT/FLOAT/DOUBLE/DECIMAL). Unsupported SqlTypeNames are not present in the map, so an UnsupportedOperationException is thrown. This is a deliberately unsupported-conversion guard, not a data error.","triggerScenarios":"Calling BigDecimalConverter.forSqlType(TypeName) with a type absent from CONVERTER_MAP, e.g. TypeName.STRING, TypeName.BOOLEAN, TypeName.TIMESTAMP, or null.","commonSituations":"Generic code that maps arbitrary schema field types to a BigDecimal-based representation, or a new Beam TypeName added later that the converter was never extended for.","solutions":["Only call forSqlType for numeric types (INT16/INT32/INT64, FLOAT, DOUBLE, DECIMAL).","Pre-convert to a supported numeric type before calling.","Add the desired mapping to CONVERTER_MAP if you own the code.","Catch UnsupportedOperationException and fall back to identity/decimal handling."],"exampleFix":"// before\nSerializableFunction<BigDecimal, ? extends Number> fn = BigDecimalConverter.forSqlType(TypeName.STRING);\n// after\nif (field.getType().getTypeName().isNumericType()) {\n  fn = BigDecimalConverter.forSqlType(field.getType().getTypeName());\n}","handlingStrategy":"type-guard","validationCode":"Set<TypeName> supported = Set.of(TypeName.INT16, TypeName.INT32, TypeName.INT64, TypeName.FLOAT, TypeName.DOUBLE, TypeName.DECIMAL);\nif (!supported.contains(typeName)) { /* route to non-BigDecimal path */ }","typeGuard":"boolean isDecimalConvertible(TypeName t) {\n  return t != null && EnumSet.of(TypeName.INT16, TypeName.INT32, TypeName.INT64, TypeName.FLOAT, TypeName.DOUBLE, TypeName.DECIMAL).contains(t);\n}","tryCatchPattern":"try { fn = BigDecimalConverter.forSqlType(typeName); }\ncatch (UnsupportedOperationException e) { fn = v -> v; /* identity or decimal passthrough */ }","preventionTips":["Only call forSqlType for numeric TypeNames","Keep a whitelist of convertible types near the call site","Update CONVERTER_MAP when adding new Beam TypeNames"],"tags":["beam-sql","type-conversion","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}