{"record":{"id":"4252510085d8fdaf","repo":"apache/beam","slug":"this-getclass-getcanonicalname-supports-integer-long-string","errorCode":null,"errorMessage":"${this.getClass().getCanonicalName()} supports Integer, Long, String and byte[] objects directly. For other types you must provide a Mapping function.","messagePattern":"(.+?) supports Integer, Long, String and byte\\[\\] objects directly\\. For other types you must provide a Mapping function\\.","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":161,"sourceCode":"\n      if (HLL_IMPLEMENTED_TYPES.contains(type)) {\n\n        HllCount.Init.Builder<T> builder = builderForType(type);\n\n        return input.apply(builder.globally()).apply(HllCount.Extract.globally());\n      }\n\n      // Boiler plate to avoid  [argument] NonNull vs Nullable\n      Contextful<Fn<T, Long>> mapping = getMapping();\n\n      if (mapping != null) {\n        return input\n            .apply(MapElements.into(TypeDescriptors.longs()).via(mapping))\n            .apply(HllCount.Init.forLongs().globally())\n            .apply(HllCount.Extract.globally());\n      }\n\n      throw new IllegalArgumentException(\n          String.format(\n              \"%s supports Integer,\"\n                  + \" Long, String and byte[] objects directly. For other types you must provide a Mapping function.\",\n              this.getClass().getCanonicalName()));\n    }\n\n    @Override\n    public void populateDisplayData(DisplayData.Builder builder) {\n      super.populateDisplayData(builder);\n      ApproximateCountDistinct.populateDisplayData(builder, getPrecision());\n    }\n  }\n\n  @AutoValue\n  public abstract static class PerKey<K, V>\n      extends PTransform<PCollection<KV<K, V>>, PCollection<KV<K, Long>>> {\n\n    public abstract int getPrecision();","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/zetasketch/src/main/java/org/apache/beam/sdk/extensions/zetasketch/ApproximateCountDistinct.java#L143-L179","documentation":"ApproximateCountDistinct.expand natively maps only Integer, Long, String, and byte[] inputs onto HllCount sketch initializers. For any other element type, with no mapping function supplied, it throws IllegalArgumentException telling the developer a Mapping function (via) must be provided.","triggerScenarios":"Applying ApproximateCountDistinct.globally() (or perKey) to a PCollection of a type other than Integer/Long/String/byte[] without calling a via()/mapping overload.","commonSituations":"Counting distinct custom POJOs, Rows, Doubles, or Booleans directly; using the generic T-typed constructor expecting automatic conversion.","solutions":["Provide a mapping function converting your type to a supported one, e.g. MapElements.into(TypeDescriptors.longs()).via(x -> x.getId()).","Convert the input PCollection to strings or bytes before counting.","Use a different sketch/approximation transform that supports your type natively.","For perKey variants, map both key and value types to supported ones."],"exampleFix":"// before\npc.apply(ApproximateCountDistinct.<MyPojo>globally());\n// after\npc.apply(MapElements.into(TypeDescriptors.longs()).via(MyPojo::getId))\n  .apply(ApproximateCountDistinct.globally());","handlingStrategy":"type-guard","validationCode":"if (!Arrays.asList(Integer.class, Long.class, String.class, byte[].class).equals(elemType.getRawType())) {\n  // require a mapping function before applying\n}","typeGuard":"boolean isHllSupported(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 pc.apply(ApproximateCountDistinct.globally());\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Mapping function\")) { /* supply via() mapping */ }\n  throw e;\n}","preventionTips":["Check element type against Integer/Long/String/byte[] before HLL counting","Always supply MapElements.via for custom POJOs","Centralize supported-type checks in pipeline builders"],"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"}