{"record":{"id":"9f55a66002b43807","repo":"dgraph-io/dgraph","slug":"repeated-id-with-non-int-float-value-for-facet-var","errorCode":null,"errorMessage":"Repeated id with non int/float value for facet var encountered.","messagePattern":"Repeated id with non int/float value for facet var encountered\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/query.go","lineNumber":1721,"sourceCode":"\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif pVal, ok := doneVars[fvar].Vals.Get(uid); !ok {\n\t\t\t\t\tfVal, err := facets.ValFor(f)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\n\t\t\t\t\tdoneVars[fvar].Vals.Set(uid, fVal)\n\t\t\t\t} else {\n\t\t\t\t\t// If the value is int/float we add them up. Else we throw an error as\n\t\t\t\t\t// many to one maps are not allowed for other types.\n\t\t\t\t\tnVal, err := facets.ValFor(f)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\n\t\t\t\t\tif nVal.Tid != types.IntID && nVal.Tid != types.FloatID {\n\t\t\t\t\t\treturn errors.Errorf(\"Repeated id with non int/float value for \" +\n\t\t\t\t\t\t\t\"facet var encountered.\")\n\t\t\t\t\t}\n\t\t\t\t\tag := aggregator{name: \"sum\"}\n\t\t\t\t\tif err := ag.Apply(pVal); err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t\tif err := ag.Apply(nVal); err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t\tfVal, err := ag.Value()\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tdoneVars[fvar].Vals.Set(uid, fVal)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":1703,"sourceCodeEnd":1739,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/query.go#L1703-L1739","documentation":"When propagating facet value variables across repeated UIDs (same id appearing multiple times), Dgraph sums facet values and requires them to be int or float. If facets.ValFor returns a value of another type (e.g. datetime, string, bool), this error is thrown because 'sum' aggregation over repeated ids cannot handle non-numeric facet values.","triggerScenarios":"Using a facet variable (facet var) on a predicate with duplicate UIDs where the facet's type is not int/float; e.g. 'friend @facets(since as f)' where f is a datetime facet and the same friend id repeats in the uid list.","commonSituations":"Facets declared as datetime/string/bool in schema but used with facet variables in aggregation contexts; queries assuming facets are numeric; schema evolved to non-numeric facet types.","solutions":["Ensure the facet used in the facet variable has an int or float type","Change the facet value type in the schema or write numeric values for that facet","Remove the facet variable usage if non-numeric facets are required and handle client-side","Deduplicate the UID list so the repeated-id summation path is not taken"],"exampleFix":"// before: 'since' facet is datetime\n{\n  me(func: uid(1)) {\n    friend @facets(s as since)\n  }\n}\n// after: use a numeric facet\n{\n  me(func: uid(1)) {\n    friend @facets(s as weight)  // weight is float\n  }\n}","handlingStrategy":"validation","validationCode":"// Confirm facet types are numeric before using facet variables in aggregation\nif facetType(pred, facet) != \"int\" && facetType(pred, facet) != \"float\" {\n    return fmt.Errorf(\"facet %s on %s must be int/float for facet variables\", facet, pred)\n}","typeGuard":"func isNumericFacet(v types.Val) bool { return v.Tid == types.IntID || v.Tid == types.FloatID }","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"non int/float value for facet var\") {\n    return fmt.Errorf(\"facet variable used with non-numeric facet: %w\", err)\n}","preventionTips":["Declare numeric facets as int/float in schema when they will be aggregated","Avoid datetime/string facets in facet-variable positions","Validate facet types in data-ingestion pipelines"],"tags":["dgraph","facets","type-mismatch","aggregation"],"backgroundTag":"non-numeric-facet-variable","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}