{"record":{"id":"dde4241992616372","repo":"hasura/graphql-engine","slug":"type-mismatch-between-the-aggregation-function-a","errorCode":null,"errorMessage":"type mismatch between the aggregation function '{aggregation_function_name}' (return type: '{aggregation_function_return_type}') and the specified boolean expression type '{boolean_expression_type}' (operand type: '{boolean_expression_operand_type}')","messagePattern":"type mismatch between the aggregation function '(.+?)' \\(return type: '(.+?)'\\) and the specified boolean expression type '(.+?)' \\(operand type: '(.+?)'\\)","errorType":"validation","errorClass":"AggregateBooleanExpressionError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs","lineNumber":183,"sourceCode":"        aggregation_function_name: AggregationFunctionName,\n    },\n\n    #[error(\n        \"the aggregation function '{aggregation_function_name}' is not defined in the aggregate expression '{aggregate_expression}'\"\n    )]\n    AggregationFunctionNotFound {\n        aggregation_function_name: AggregationFunctionName,\n        aggregate_expression: Qualified<AggregateExpressionName>,\n    },\n\n    #[error(\n        \"could not find a scalar-operanded boolean expression type named '{boolean_expression_type}'\"\n    )]\n    ScalarBooleanExpressionTypeNotFound {\n        boolean_expression_type: BooleanExpressionTypeIdentifier,\n    },\n\n    #[error(\n        \"type mismatch between the aggregation function '{aggregation_function_name}' (return type: '{aggregation_function_return_type}') and the specified boolean expression type '{boolean_expression_type}' (operand type: '{boolean_expression_operand_type}')\"\n    )]\n    AggregationFunctionTypeMismatch {\n        aggregation_function_name: AggregationFunctionName,\n        aggregation_function_return_type: QualifiedTypeName,\n        boolean_expression_type: BooleanExpressionTypeIdentifier,\n        boolean_expression_operand_type: QualifiedTypeName,\n    },\n\n    #[error(\n        \"the aggregation function '{aggregation_function_name}' returns an array type ({aggregation_function_return_type}). Array types are not supported in aggregate comparisons\"\n    )]\n    ComparisonAgainstArrayTypesNotSupported {\n        aggregation_function_name: AggregationFunctionName,\n        aggregation_function_return_type: QualifiedTypeReference,\n    },\n\n    #[error(","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs#L165-L201","documentation":"During resolution of an aggregate boolean expression, the aggregation function's return type must match the operand type of the chosen boolean expression type. This error is thrown when comparing an aggregation function (e.g. avg, sum, min, max) whose return type differs from the scalar type the boolean expression type operates on, making the comparison ill-typed.","triggerScenarios":"Comparing an aggregate like avg (returns Float/numeric) against a boolean expression type whose operand is e.g. String or Int; specifying filter expressions that use a boolean_expression_type built for a different scalar type than the aggregate's output type.","commonSituations":"Switching an aggregation function in metadata (e.g. from count to avg) without updating the boolean expression type used in the comparison; boolean expression types auto-generated per-type being mixed up when hand-writing comparative aggregate filters; connector returning a different scalar type after a version upgrade.","solutions":["Check the aggregation function's return type in the connector's capability/schema and pick a boolean expression type whose operand type matches it exactly","If the scalar types should be equivalent, fix the underlying scalar type mapping in metadata so the qualified names match","Update the boolean expression type used in the aggregate comparison to one defined on the aggregate's return type"],"exampleFix":"// before\naggregate: { avg: { field: price } }\nfilter: { avg: { _eq: $val } } // _eq operand Int but avg returns Float\n\n// after\naggregate: { avg: { field: price } }\nfilter: { avg: { _eq: $val } } // use Float-typed comparison / matching bool exp type","handlingStrategy":"validation","validationCode":"// check aggregate return type matches bool exp operand type before building filter\nassert_eq!(agg_fn.return_type.qualified_name(), bool_exp.operand_type.qualified_name(),\n    \"aggregate/boolean-expression operand type mismatch\");","typeGuard":"fn types_compatible(agg_ret: &QualifiedTypeName, operand: &QualifiedTypeName) -> bool {\n    agg_ret == operand\n}","tryCatchPattern":"match resolve(expr) {\n    Err(ResolveError::AggregationFunctionTypeMismatch { aggregation_function_name, .. }) => {\n        // pick a bool exp type matching the aggregate's return type and retry once\n    }\n    r => r,\n}","preventionTips":["Generate boolean expression type usage from the aggregate's return type","Type-check metadata against connector capabilities in CI","Avoid hand-writing aggregate comparisons when generated types exist"],"tags":["rust","type-mismatch","aggregate","boolean-expression","metadata"],"backgroundTag":null,"analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}