{"record":{"id":"980e2e2c8829e2e4","repo":"apache/beam","slug":"type-not-supported-input","errorCode":null,"errorMessage":"Type not supported ${input}","messagePattern":"Type not supported (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/zetasketch/src/main/java/org/apache/beam/sdk/extensions/zetasketch/ApproximateCountDistinct.java","lineNumber":278,"sourceCode":"\n    @SuppressWarnings(\"rawtypes\")\n    HllCount.Init.Builder builder = null;\n\n    if (input.equals(TypeDescriptors.strings())) {\n      builder = HllCount.Init.forStrings();\n    }\n    if (input.equals(TypeDescriptors.longs())) {\n      builder = HllCount.Init.forLongs();\n    }\n    if (input.equals(TypeDescriptors.integers())) {\n      builder = HllCount.Init.forIntegers();\n    }\n    if (input.equals(new TypeDescriptor<byte[]>() {})) {\n      builder = HllCount.Init.forBytes();\n    }\n\n    if (builder == null) {\n      throw new IllegalArgumentException(String.format(\"Type not supported %s\", input));\n    }\n\n    // Safe to ignore warning, as we know the type based on the check we do above.\n    @SuppressWarnings(\"unchecked\")\n    HllCount.Init.Builder<T> output = (HllCount.Init.Builder<T>) builder;\n\n    return output;\n  }\n}\n","sourceCodeStart":260,"sourceCodeEnd":288,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/zetasketch/src/main/java/org/apache/beam/sdk/extensions/zetasketch/ApproximateCountDistinct.java#L260-L288","documentation":"ApproximateCountDistinct.builderForType selects the matching HllCount.Init.Builder for the input TypeDescriptor. If the descriptor matches none of Integer, Long, String, or byte[], builder stays null and IllegalArgumentException \"Type not supported\" is thrown. This is the type-dispatch guard used by the T-typed construction path.","triggerScenarios":"Constructing ApproximateCountDistinct with a generic type T (e.g. via of()/globally for Double, Boolean, or a custom class) whose TypeDescriptor has no registered HllCount initializer.","commonSituations":"Using ApproximateCountDistinct.of(new TypeDescriptor<Double>(){}) expecting Double support; generic helper methods parameterized over T hitting the unsupported branch at runtime.","solutions":["Use one of the explicitly supported types: Integer, Long, String, or byte[].","Map your input to a supported type with MapElements.via before counting.","Add an explicit mapping overload call instead of relying on generic type dispatch.","Inspect the message's type string to confirm which descriptor failed the match."],"exampleFix":"// before\nApproximateCountDistinct.of(new TypeDescriptor<Double>() {});\n// after\npc.apply(MapElements.into(TypeDescriptors.longs()).via(d -> (long) Double.doubleToLongBits(d)))\n  .apply(ApproximateCountDistinct.globally());","handlingStrategy":"type-guard","validationCode":"if (!Arrays.asList(Integer.class, Long.class, String.class, byte[].class).contains(type.getRawType())) {\n  throw new IllegalArgumentException(\"ApproximateCountDistinct unsupported type: \" + type);\n}","typeGuard":"boolean isCountDistinctSupported(TypeDescriptor<?> t) {\n  Class<?> c = t.getRawType();\n  return c == Integer.class || c == Long.class || c == String.class || c == byte[].class;\n}","tryCatchPattern":"try {\n  return ApproximateCountDistinct.of(type);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Type not supported\")) { /* map to supported type */ }\n  throw e;\n}","preventionTips":["Restrict generic T to supported types with bounded type parameters","Pre-map exotic types with MapElements.via at pipeline edges","Unit-test type dispatch for each ApproximateCountDistinct overload"],"tags":["apache-beam","java","zetasketch","hll","unsupported-type"],"backgroundTag":"unsupported-dtype","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}