{"record":{"id":"68c6e1fa6ba5ad88","repo":"apache/beam","slug":"found-multiple-definitions-of-aggregate-function","errorCode":null,"errorMessage":"Found multiple definitions of aggregate function ${functionName} in ${jarPath}.","messagePattern":"Found multiple definitions of aggregate function (.+?) in (.+?)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/JavaUdfLoader.java","lineNumber":237,"sourceCode":"          .userDefinedScalarFunctions()\n          .forEach(\n              (functionName, implementation) -> {\n                List<String> functionPath = ImmutableList.copyOf(functionName.split(\"\\\\.\"));\n                if (scalarFunctions.containsKey(functionPath)) {\n                  throw new IllegalArgumentException(\n                      String.format(\n                          \"Found multiple definitions of scalar function %s in %s.\",\n                          functionName, jarPath));\n                }\n                scalarFunctions.put(functionPath, implementation);\n              });\n      provider\n          .userDefinedAggregateFunctions()\n          .forEach(\n              (functionName, implementation) -> {\n                List<String> functionPath = ImmutableList.copyOf(functionName.split(\"\\\\.\"));\n                if (aggregateFunctions.containsKey(functionPath)) {\n                  throw new IllegalArgumentException(\n                      String.format(\n                          \"Found multiple definitions of aggregate function %s in %s.\",\n                          functionName, jarPath));\n                }\n                aggregateFunctions.put(functionPath, implementation);\n              });\n    }\n    if (providersCount == 0) {\n      throw new ProviderNotFoundException(\n          String.format(\n              \"No %s implementation found in %s. Create a class implementing %s and annotate it with @AutoService(%s.class).\",\n              UdfProvider.class.getSimpleName(),\n              jarPath,\n              UdfProvider.class.getSimpleName(),\n              UdfProvider.class.getSimpleName()));\n    }\n    LOG.info(\n        \"Loaded {} implementations of {} from {} with {} scalar function(s).\",","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/JavaUdfLoader.java#L219-L255","documentation":"JavaUdfLoader.loadJar() throws IllegalArgumentException when two aggregate functions in the jar resolve to the same function path key. Duplicate registration in userDefinedAggregateFunctions() is rejected so lookup results are unambiguous. Same mechanism as the scalar-function duplicate check but over the aggregateFunctions map.","triggerScenarios":"loadJar processing a jar whose provider returns two entries in userDefinedAggregateFunctions() that split into the identical List<String> path.","commonSituations":"The same aggregate registered twice with identical names; merging UDF jars where both define an aggregate with the same fully-qualified name; copy-paste duplication in the provider implementation.","solutions":["Remove the duplicate aggregate registration or rename one of them.","Namespace colliding aggregates under different packages/fully-qualified names.","Rebuild and redeploy the corrected jar.","Audit userDefinedAggregateFunctions() for key collisions before packaging."],"exampleFix":"// before\nreturn ImmutableMap.of(\"my.agg\", aggA, \"my.agg\", aggB);\n// after\nreturn ImmutableMap.of(\"my.agg\", aggA, \"my.agg2\", aggB);","handlingStrategy":"try-catch","validationCode":"Set<List<String>> seen = new HashSet<>();\nfor (String name : aggregateMap.keySet()) {\n  if (!seen.add(ImmutableList.copyOf(name.split(\"\\\\.\")))) {\n    throw new IllegalStateException(\"Duplicate aggregate fn: \" + name);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  udfLoader.loadAggregateFunction(fnPath, jarPath);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Found multiple definitions of aggregate function\")) {\n    LOG.error(\"Duplicate aggregate registration in {}: {}\", jarPath, e.getMessage());\n  }\n  throw e;\n}","preventionTips":["Keep userDefinedAggregateFunctions() keys unique","Namespace aggregates by package to avoid merge collisions","Run jar-loading unit tests in CI before publishing the UDF jar","Review provider maps with a linter for duplicate keys"],"tags":["udf","duplicate","aggregate","beam"],"backgroundTag":"conflicting-config-options","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}