{"record":{"id":"9372090917ff423e","repo":"hasura/graphql-engine","slug":"the-aggregate-expression-name-has-duplicate-defi-937209","errorCode":null,"errorMessage":"the aggregate expression {name} has duplicate definitions of the aggregation function '{function_name}'","messagePattern":"the aggregate expression (.+?) has duplicate definitions of the aggregation function '(.+?)'","errorType":"validation","errorClass":"AggregateExpressionError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/aggregates/types.rs","lineNumber":196,"sourceCode":"    )]\n    AggregateOperandObjectFieldTypeMismatch {\n        name: Qualified<AggregateExpressionName>,\n        operand_type: Qualified<CustomTypeName>,\n        field_name: FieldName,\n        field_type: QualifiedTypeReference,\n        field_aggregate_exp_name: Qualified<AggregateExpressionName>,\n        field_aggregate_exp_operand_type: QualifiedTypeName,\n    },\n\n    #[error(\n        \"the aggregate expression {name} specifies an operand scalar type that cannot be found: {type_name}\"\n    )]\n    AggregateOperandScalarTypeNotFound {\n        name: Qualified<AggregateExpressionName>,\n        type_name: Qualified<CustomTypeName>,\n    },\n\n    #[error(\n        \"the aggregate expression {name} has duplicate definitions of the aggregation function '{function_name}'\"\n    )]\n    AggregateOperandFunctionDuplicated {\n        name: Qualified<AggregateExpressionName>,\n        function_name: AggregationFunctionName,\n    },\n\n    #[error(\n        \"the aggregate expression {name} specifies an aggregation function '{function_name}' that uses an unknown type for its return type: {type_name}\"\n    )]\n    AggregateOperandFunctionUnknownReturnType {\n        name: Qualified<AggregateExpressionName>,\n        function_name: AggregationFunctionName,\n        type_name: CustomTypeName,\n    },\n\n    #[error(\n        \"the aggregate expression {name} defines an aggregation function mapping to an unknown data connector: {data_connector_name}\"","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/aggregates/types.rs#L178-L214","documentation":"Thrown during metadata resolution when a single aggregate expression in OpenDD metadata declares the same aggregation function (e.g. 'avg' or 'count') more than once. Each function must be defined exactly once per aggregate expression so the resolver can build a deterministic mapping of function to return type and data-connector mappings.","triggerScenarios":"An OpenDD `AggregateExpression` kind object whose `functions` array (or function map) contains two entries with the same `AggregationFunctionName` for the same aggregate expression. Surfaced when `ddn run`/metadata resolve executes the aggregates resolution stage.","commonSituations":"Copy-pasting a function block within the aggregate expression YAML and forgetting to change the function name; merging metadata branches that both added the same function; hand-editing generated metadata under `engine/metadata` instead of using `ddn` CLI.","solutions":["Open the named aggregate expression in your metadata (usually under the `kinds: AggregateExpression` file) and locate the duplicate entries for the named function","Delete or rename the duplicate so each function name appears exactly once in that aggregate expression","Re-run `ddn build` / metadata resolution to confirm the error is gone","Avoid hand-editing generated aggregate metadata; regenerate with the CLI"],"exampleFix":"# before\nfunctions:\n  - name: avg\n    return_type: Float\n  - name: avg\n    return_type: Float\n# after\nfunctions:\n  - name: avg\n    return_type: Float\n  - name: max\n    return_type: Float","handlingStrategy":"validation","validationCode":"# In a CI metadata-lint script, parse the AggregateExpression YAML/JSON:\nimport collections, yaml\nfor doc in yaml.safe_load_all(open('metadata.yaml')):\n    if doc.get('kind') == 'AggregateExpression':\n        fns = [f['name'] for f in doc.get('functions', [])]\n        dupes = [n for n, c in collections.Counter(fns).items() if c > 1]\n        assert not dupes, f\"{doc['name']}: duplicate functions {dupes}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `ddn build` (or metadata resolve) in CI before deploying","Don't hand-edit generated metadata under engine/metadata","Lint aggregate expressions for duplicate function names in a pre-commit hook"],"tags":["opendd","metadata","aggregates","duplicate"],"backgroundTag":"metadata-schema-validation-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}