hasura/graphql-engine · error · AggregateExpressionError

the aggregate expression {name} has duplicate definitions of

Error message

the aggregate expression {name} has duplicate definitions of the aggregation function '{function_name}'

What it means

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.

Source

Thrown at v3/crates/metadata-resolve/src/stages/aggregates/types.rs:196

    )]
    AggregateOperandObjectFieldTypeMismatch {
        name: Qualified<AggregateExpressionName>,
        operand_type: Qualified<CustomTypeName>,
        field_name: FieldName,
        field_type: QualifiedTypeReference,
        field_aggregate_exp_name: Qualified<AggregateExpressionName>,
        field_aggregate_exp_operand_type: QualifiedTypeName,
    },

    #[error(
        "the aggregate expression {name} specifies an operand scalar type that cannot be found: {type_name}"
    )]
    AggregateOperandScalarTypeNotFound {
        name: Qualified<AggregateExpressionName>,
        type_name: Qualified<CustomTypeName>,
    },

    #[error(
        "the aggregate expression {name} has duplicate definitions of the aggregation function '{function_name}'"
    )]
    AggregateOperandFunctionDuplicated {
        name: Qualified<AggregateExpressionName>,
        function_name: AggregationFunctionName,
    },

    #[error(
        "the aggregate expression {name} specifies an aggregation function '{function_name}' that uses an unknown type for its return type: {type_name}"
    )]
    AggregateOperandFunctionUnknownReturnType {
        name: Qualified<AggregateExpressionName>,
        function_name: AggregationFunctionName,
        type_name: CustomTypeName,
    },

    #[error(
        "the aggregate expression {name} defines an aggregation function mapping to an unknown data connector: {data_connector_name}"

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Open the named aggregate expression in your metadata (usually under the `kinds: AggregateExpression` file) and locate the duplicate entries for the named function
  2. Delete or rename the duplicate so each function name appears exactly once in that aggregate expression
  3. Re-run `ddn build` / metadata resolution to confirm the error is gone
  4. Avoid hand-editing generated aggregate metadata; regenerate with the CLI

Example fix

# before
functions:
  - name: avg
    return_type: Float
  - name: avg
    return_type: Float
# after
functions:
  - name: avg
    return_type: Float
  - name: max
    return_type: Float
Defensive patterns

Strategy: validation

Validate before calling

# In a CI metadata-lint script, parse the AggregateExpression YAML/JSON:
import collections, yaml
for doc in yaml.safe_load_all(open('metadata.yaml')):
    if doc.get('kind') == 'AggregateExpression':
        fns = [f['name'] for f in doc.get('functions', [])]
        dupes = [n for n, c in collections.Counter(fns).items() if c > 1]
        assert not dupes, f"{doc['name']}: duplicate functions {dupes}"

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/9372090917ff423e. Report an issue: GitHub.