{"record":{"id":"01b6ce833fa75fc5","repo":"apache/beam","slug":"unknown-policy-policy","errorCode":null,"errorMessage":"Unknown policy ${policy}","messagePattern":"Unknown policy (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/euphoria/src/main/java/org/apache/beam/sdk/extensions/euphoria/core/client/operator/Distinct.java","lineNumber":384,"sourceCode":"      return MapElements.named(getName().orElse(\"\") + \"::extract-keys\")\n          .of(distinct)\n          .using(KV::getKey, input.getTypeDescriptor())\n          .output();\n    }\n    UnaryFunction<PCollection<InputT>, PCollection<InputT>> transformFn = getTransformFn();\n    return transformFn.apply(input);\n  }\n\n  private UnaryFunction<PCollection<InputT>, PCollection<InputT>> getTransformFn() {\n    switch (policy) {\n      case NEWEST:\n      case OLDEST:\n        String name = getName().orElse(null);\n        return input -> input.apply(TimestampExtractTransform.of(name, this::reduceTimestamped));\n      case ANY:\n        return this::reduceSelectingAny;\n      default:\n        throw new IllegalArgumentException(\"Unknown policy \" + policy);\n    }\n  }\n\n  private PCollection<InputT> reduceSelectingAny(PCollection<InputT> input) {\n    return ReduceByKey.named(getName().orElse(null))\n        .of(input)\n        .keyBy(getKeyExtractor(), getKeyType().orElse(null))\n        .valueBy(e -> e, getOutputType().orElse(null))\n        .combineBy(values -> nonEmpty(values.findAny()), getOutputType().orElse(null))\n        .outputValues();\n  }\n\n  private PCollection<InputT> reduceTimestamped(PCollection<KV<Long, InputT>> input) {\n    CombinableReduceFunction<KV<Long, InputT>> select = getReduceFn();\n    PCollection<KV<Long, InputT>> outputValues =\n        ReduceByKey.named(getName().orElse(null))\n            .of(input)\n            .keyBy(e -> getKeyExtractor().apply(e.getValue()), getKeyType().orElse(null))","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/euphoria/src/main/java/org/apache/beam/sdk/extensions/euphoria/core/client/operator/Distinct.java#L366-L402","documentation":"Distinct.withNaturalKeys/apply logic selects a reduce strategy based on the configured TimestampPolicy. The getTransformFn switch handles OLDEST and ANY; any other policy value (e.g. NEWEST, or a policy enum extended in a newer version not handled here) falls through to default and throws IllegalArgumentException 'Unknown policy'.","triggerScenarios":"Building a Distinct operator with Distinct.TimestampPolicy set to a value not covered by the switch (typically NEWEST or an enum value added after this code was written), then triggering the operator's expansion via transformFn.","commonSituations":"Copying example code that references a policy variant supported elsewhere but not in this euphoria extension; upgrading the Beam version so the enum gained a new constant while the switch wasn't updated.","solutions":["Use only TimestampPolicy.OLDEST or TimestampPolicy.ANY with this operator.","If NEWEST-like behavior is needed, implement a custom ReduceByKey pipeline instead of relying on Distinct.","Check the Beam version: if a newer version handles the policy, upgrade the org.apache.beam euphoria extension dependency."],"exampleFix":"// before\nDistinct.named(\"d\").withTimestampPolicy(Distinct.TimestampPolicy.NEWEST);\n// after\nDistinct.named(\"d\").withTimestampPolicy(Distinct.TimestampPolicy.OLDEST);","handlingStrategy":"validation","validationCode":"if (policy != Distinct.TimestampPolicy.OLDEST && policy != Distinct.TimestampPolicy.ANY) {\n  throw new IllegalArgumentException(\"Unsupported policy for Distinct: \" + policy);\n}","typeGuard":null,"tryCatchPattern":"try {\n  expansion = getTransformFnFor(policy);\n} catch (IllegalArgumentException e) {\n  LOG.warn(\"falling back to TimestampPolicy.ANY\");\n  expansion = getTransformFnFor(Distinct.TimestampPolicy.ANY);\n}","preventionTips":["Restrict policy choices in configuration to OLDEST or ANY.","Re-check supported enum values after upgrading Beam euphoria.","Add a switch-coverage test over all TimestampPolicy constants."],"tags":["java","illegal-argument","enum","euphoria","distinct"],"backgroundTag":"invalid-enum-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}