{"record":{"id":"63ce9c18630dd28a","repo":"apache/beam","slug":"cannot-set-both-a-global-and-per-tag-fields","errorCode":null,"errorMessage":"Cannot set both a global and per-tag fields.","messagePattern":"Cannot set both a global and per-tag fields\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/CoGroup.java","lineNumber":728,"sourceCode":"    }\n\n    private Impl(JoinArguments joinArgs, String keyFieldName) {\n      this.joinArgs = joinArgs;\n      this.keyFieldName = keyFieldName;\n    }\n\n    public Impl withKeyField(String keyFieldName) {\n      return new Impl(joinArgs, keyFieldName);\n    }\n\n    /**\n     * Select the following fields for the specified PCollection with the specified join args.\n     *\n     * <p>Each PCollection in the input must have fields specified for the join key.\n     */\n    public Impl join(String tag, By clause) {\n      if (joinArgs.allInputsJoinArgs != null) {\n        throw new IllegalStateException(\"Cannot set both a global and per-tag fields.\");\n      }\n      return new Impl(joinArgs.with(tag, clause), keyFieldName);\n    }\n\n    /** Expand the join into individual rows, similar to SQL joins. */\n    public ExpandCrossProduct crossProductJoin() {\n      return new ExpandCrossProduct(joinArgs);\n    }\n\n    @Override\n    public PCollection<Row> expand(PCollectionTuple input) {\n      verify(input, joinArgs);\n\n      JoinInformation joinInformation =\n          JoinInformation.from(\n              input, joinArgs::getFieldAccessDescriptor, joinArgs::getSideInputSource);\n\n      Collection<PCollectionView<Map<Row, Iterable<Row>>>> views =","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/CoGroup.java#L710-L746","documentation":"CoGroup supports either a global key-fields clause (byFields applying to all inputs) or per-tag join(tag, By) clauses, but not both. The Impl's join() method throws IllegalStateException if joinArgs.allInputsJoinArgs was already set, enforcing this mutual exclusivity.","triggerScenarios":"Calling CoGroup.byFields(...).join(\"tag\", By.field(...)) — i.e. mixing the global byFields() call with any per-tag join() call on the same builder.","commonSituations":"Starting a join with the convenient global byFields() and later trying to customize one input's key fields; copy-pasting builder code that combines both styles from examples.","solutions":["Use per-tag join(tag, By...) for ALL inputs, dropping the global byFields() call.","Or keep the global byFields() and remove all join(tag, ...) calls if all inputs share the same key fields.","Model per-input customization by giving each tag its own By clause that duplicates the common fields plus extras."],"exampleFix":"// before (mixing)\nCoGroup coGroup = CoGroup.byFields(\"key\")\n    .join(\"b\", By.field(\"otherKey\"))\n    .from(tuple);\n// after: all per-tag\nCoGroup coGroup = CoGroup\n    .join(\"a\", By.field(\"key\"))\n    .join(\"b\", By.field(\"otherKey\"))\n    .from(tuple);","handlingStrategy":"validation","validationCode":"if (usedGlobalByFields && perTagJoinsUsed) {\n  throw new IllegalStateException(\"Cannot set both a global and per-tag fields.\");\n}","typeGuard":null,"tryCatchPattern":"try { impl = builder.join(tag, by); } catch (IllegalStateException e) { if (e.getMessage().contains(\"global and per-tag\")) { /* rebuild builder with one style */ } else throw e; }","preventionTips":["Pick one style up front: either byFields(...) or join(tag, By...) for every input","Wrap builder construction in a helper method enforcing the choice","Review builder chains for mixed byFields/join calls in code review"],"tags":["java","apache-beam","co-group","join","conflicting-options"],"backgroundTag":"mutually-exclusive-options","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"}