dgraph-io/dgraph · error

groupby is not supported in rdf output format

Error message

groupby is not supported in rdf output format

What it means

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.

Source

Thrown at query/outputrdf.go:216

	if len(val) > math.MaxInt-overhead {
		// Extremely unlikely, but handle overflow case
		// Fall back to append without pre-allocation
		buf := make([]byte, 0)
		buf = append(buf, '<')
		buf = append(buf, val...)
		buf = append(buf, '>')
		return buf
	}
	buf := make([]byte, 0, overhead+len(val))
	buf = append(buf, '<')
	buf = append(buf, val...)
	buf = append(buf, '>')
	return buf
}

func validateSubGraphForRDF(sg *SubGraph) error {
	if sg.IsGroupBy() {
		return errors.New("groupby is not supported in rdf output format")
	}
	uidCount := sg.Attr == "uid" && sg.Params.DoCount && sg.IsInternal()
	if uidCount {
		return errors.New("uid count is not supported in the rdf output format")
	}
	if sg.Params.Normalize {
		return errors.New("normalize directive is not supported in the rdf output format")
	}
	if sg.Params.IgnoreReflex {
		return errors.New("ignorereflex directive is not supported in the rdf output format")
	}
	if sg.SrcFunc != nil && sg.SrcFunc.Name == "checkpwd" {
		return errors.New("chkpwd function is not supported in the rdf output format")
	}
	if sg.Params.Facet != nil && !sg.Params.ExpandAll {
		return errors.New("facets are not supported in the rdf output format")
	}
	return nil

View on GitHub (pinned to 759e242be6)

Solutions

  1. Remove the groupby block from the query or switch the output format to JSON
  2. Compute grouping client-side from the JSON result instead of server-side groupby
  3. Use count/aggregate directives compatible with RDF output if a simple count is all that is needed

Example fix

// before
{ me(func: eq(name, "Alice")) { groupby(friend) { count(uid) } } }
// after
{ me(func: eq(name, "Alice")) { friend { name } } } // group client-side, or use JSON output
Defensive patterns

Strategy: validation

Validate before calling

// Go: before requesting RDF output, check query for groupby
if strings.Contains(strings.ToLower(query), "groupby(") {
    // switch to JSON output or strip groupby
    return errors.New("query uses groupby; RDF output unsupported")
}

Type guard

func querySupportsRDF(dql string) bool {
    return !strings.Contains(strings.ToLower(dql), "groupby(")
}

Try / catch

res, err := client.NewTxn().QueryRDF(ctx, dql)
if err != nil && strings.Contains(err.Error(), "groupby is not supported in rdf") {
    res, err = client.NewTxn().Query(ctx, dql) // fallback to JSON
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/59629240a6d927c9. Report an issue: GitHub.