{"record":{"id":"4cc2b3685dcc7092","repo":"apache/beam","slug":"this-getclass-getcanonicalname-supports-integer-long-string-4cc2b3","errorCode":null,"errorMessage":"${this.getClass().getCanonicalName()} supports Integer, Long, String and byte[] objects directly not for ${type} type, you must provide a Mapping use via.","messagePattern":"(.+?) supports Integer, Long, String and byte\\[\\] objects directly not for (.+?) type, you must provide a Mapping use via\\.","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":237,"sourceCode":"        return input.apply(builder.perKey()).apply(HllCount.Extract.perKey());\n      }\n\n      // Boiler plate to avoid  [argument] NonNull vs Nullable\n      Contextful<Fn<KV<K, V>, KV<K, Long>>> mapping = getMapping();\n\n      if (mapping != null) {\n        Coder<K> keyCoder = ((KvCoder<K, V>) input.getCoder()).getKeyCoder();\n        return input\n            .apply(\n                MapElements.into(\n                        TypeDescriptors.kvs(\n                            keyCoder.getEncodedTypeDescriptor(), TypeDescriptors.longs()))\n                    .via(mapping))\n            .apply(HllCount.Init.forLongs().perKey())\n            .apply(HllCount.Extract.perKey());\n      }\n\n      throw new IllegalArgumentException(\n          String.format(\n              \"%s supports Integer,\"\n                  + \" Long, String and byte[] objects directly not for %s type, you must provide a Mapping use via.\",\n              this.getClass().getCanonicalName(), type.toString()));\n    }\n\n    @Override\n    public void populateDisplayData(DisplayData.Builder builder) {\n      super.populateDisplayData(builder);\n      ApproximateCountDistinct.populateDisplayData(builder, getPrecision());\n    }\n  }\n\n  /////////////////////////////////////////////////////////////////////////////\n\n  private static void populateDisplayData(DisplayData.Builder builder, Integer precision) {\n    builder.add(DisplayData.item(\"precision\", precision).withLabel(\"Precision\"));\n  }","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/zetasketch/src/main/java/org/apache/beam/sdk/extensions/zetasketch/ApproximateCountDistinct.java#L219-L255","documentation":"The per-key variant of ApproximateCountDistinct validates the encoded key/value type descriptors before wiring HllCount.Init.perKey(). When the input type is not one of the directly supported types (Integer, Long, String, byte[]), it throws IllegalArgumentException naming the offending type and instructing the developer to supply a mapping via via().","triggerScenarios":"Applying ApproximateCountDistinct perKey to a KV PCollection whose key or value type is not Integer/Long/String/byte[] and no mapping function was supplied.","commonSituations":"Counting distinct values per key where values are Doubles, POJOs, or Rows; schema-typed pipelines feeding Rows into HLL counting directly.","solutions":["Supply a mapping function (e.g. via kv -> kv.getValue().toString()) to convert to a supported type.","Pre-map the PCollection with MapElements into longs/strings/bytes before perKey counting.","Serialize unsupported values to byte[] explicitly.","Check the message's printed type to see exactly which side (key/value) is unsupported."],"exampleFix":"// before\nkvPc.apply(ApproximateCountDistinct.<String, Double>perKey());\n// after\nkvPc.apply(MapElements.into(TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.longs()))\n    .via(kv -> KV.of(kv.getKey(), Double.doubleToLongBits(kv.getValue()))))\n  .apply(ApproximateCountDistinct.perKey());","handlingStrategy":"validation","validationCode":"if (!isHllSupported(kvType.getKeyType()) || !isHllSupported(kvType.getValueType())) {\n  // supply mapping before perKey counting\n}","typeGuard":"boolean isHllKvSupported(TypeDescriptor<KV<?, ?>> t) {\n  return isHllSupported(t.getKeyType()) && isHllSupported(t.getValueType());\n}","tryCatchPattern":"try {\n  return kvPc.apply(ApproximateCountDistinct.perKey());\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"you must provide a Mapping\")) { /* map key/value */ }\n  throw e;\n}","preventionTips":["Verify KV key and value types both map to HllCount-supported types","Convert Doubles via doubleToLongBits before perKey counting","Add type assertions in pipeline construction code"],"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"}