{"record":{"id":"59629240a6d927c9","repo":"dgraph-io/dgraph","slug":"groupby-is-not-supported-in-rdf-output-format","errorCode":null,"errorMessage":"groupby is not supported in rdf output format","messagePattern":"groupby is not supported in rdf output format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/outputrdf.go","lineNumber":216,"sourceCode":"\tif len(val) > math.MaxInt-overhead {\n\t\t// Extremely unlikely, but handle overflow case\n\t\t// Fall back to append without pre-allocation\n\t\tbuf := make([]byte, 0)\n\t\tbuf = append(buf, '<')\n\t\tbuf = append(buf, val...)\n\t\tbuf = append(buf, '>')\n\t\treturn buf\n\t}\n\tbuf := make([]byte, 0, overhead+len(val))\n\tbuf = append(buf, '<')\n\tbuf = append(buf, val...)\n\tbuf = append(buf, '>')\n\treturn buf\n}\n\nfunc validateSubGraphForRDF(sg *SubGraph) error {\n\tif sg.IsGroupBy() {\n\t\treturn errors.New(\"groupby is not supported in rdf output format\")\n\t}\n\tuidCount := sg.Attr == \"uid\" && sg.Params.DoCount && sg.IsInternal()\n\tif uidCount {\n\t\treturn errors.New(\"uid count is not supported in the rdf output format\")\n\t}\n\tif sg.Params.Normalize {\n\t\treturn errors.New(\"normalize directive is not supported in the rdf output format\")\n\t}\n\tif sg.Params.IgnoreReflex {\n\t\treturn errors.New(\"ignorereflex directive is not supported in the rdf output format\")\n\t}\n\tif sg.SrcFunc != nil && sg.SrcFunc.Name == \"checkpwd\" {\n\t\treturn errors.New(\"chkpwd function is not supported in the rdf output format\")\n\t}\n\tif sg.Params.Facet != nil && !sg.Params.ExpandAll {\n\t\treturn errors.New(\"facets are not supported in the rdf output format\")\n\t}\n\treturn nil","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/outputrdf.go#L198-L234","documentation":"Dgraph's RDF output format does not support the groupby directive. Before serializing a query result as RDF, ToRDF/castToRDF calls validateSubGraphForRDF, which rejects any SubGraph where IsGroupBy() is true because grouping has no representation in RDF output.","triggerScenarios":"Running a query with a groupby block (e.g. `groupby(uid) { count(uid) }`) while requesting output in RDF format (query parameter or HTTP header output-format=rdf).","commonSituations":"Users migrating JSON-based queries to RDF output for triple export; tools that always request RDF output but pass through user queries containing groupby aggregations.","solutions":["Remove the groupby block from the query or switch the output format to JSON","Compute grouping client-side from the JSON result instead of server-side groupby","Use count/aggregate directives compatible with RDF output if a simple count is all that is needed"],"exampleFix":"// before\n{ me(func: eq(name, \"Alice\")) { groupby(friend) { count(uid) } } }\n// after\n{ me(func: eq(name, \"Alice\")) { friend { name } } } // group client-side, or use JSON output","handlingStrategy":"validation","validationCode":"// Go: before requesting RDF output, check query for groupby\nif strings.Contains(strings.ToLower(query), \"groupby(\") {\n    // switch to JSON output or strip groupby\n    return errors.New(\"query uses groupby; RDF output unsupported\")\n}","typeGuard":"func querySupportsRDF(dql string) bool {\n    return !strings.Contains(strings.ToLower(dql), \"groupby(\")\n}","tryCatchPattern":"res, err := client.NewTxn().QueryRDF(ctx, dql)\nif err != nil && strings.Contains(err.Error(), \"groupby is not supported in rdf\") {\n    res, err = client.NewTxn().Query(ctx, dql) // fallback to JSON\n}","preventionTips":["Keep RDF export queries in a dedicated allowlist of simple traversal queries","Detect groupby in user-supplied queries before selecting RDF output","Prefer JSON output and convert to RDF client-side"],"tags":["dgraph","rdf","groupby","query-validation"],"backgroundTag":"feature-not-supported-in-rdf-output","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}