MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / parseGroupby

Function parseGroupby

dql/parser.go:2359–2431  ·  view source on GitHub ↗

parseGroupby parses the groupby directive.

(it *lex.ItemIterator, gq *GraphQuery)

Source from the content-addressed store, hash-verified

2357
2358// parseGroupby parses the groupby directive.
2359func parseGroupby(it *lex.ItemIterator, gq *GraphQuery) error {
2360 count := 0
2361 expectArg := true
2362 it.Next()
2363 item := it.Item()
2364 alias := ""
2365 if item.Typ != itemLeftRound {
2366 return item.Errorf("Expected a left round after groupby")
2367 }
2368
2369loop:
2370 for it.Next() {
2371 item := it.Item()
2372 switch item.Typ {
2373 case itemRightRound:
2374 break loop
2375 case itemComma:
2376 if expectArg {
2377 return item.Errorf("Expected a predicate but got comma")
2378 }
2379 expectArg = true
2380 case itemName:
2381 if !expectArg {
2382 return item.Errorf("Expected a comma or right round but got: %v", item.Val)
2383 }
2384
2385 val := collectName(it, item.Val)
2386 peekIt, err := it.Peek(1)
2387 if err != nil {
2388 return err
2389 }
2390 if peekIt[0].Typ == itemColon {
2391 if alias != "" {
2392 return item.Errorf("Expected predicate after %s:", alias)
2393 }
2394 if validKey(val) {
2395 return item.Errorf("Can't use keyword %s as alias in groupby", val)
2396 }
2397 alias = val
2398 it.Next() // Consume the itemColon
2399 continue
2400 }
2401
2402 var langs []string
2403 items, err := it.Peek(1)
2404 if err == nil && items[0].Typ == itemAt {
2405 it.Next() // consume '@'
2406 it.Next() // move forward
2407 langs, err = parseLanguageList(it)
2408 if err != nil {
2409 return err
2410 }
2411 }
2412 attrLang := GroupByAttr{
2413 Attr: val,
2414 Alias: alias,
2415 Langs: langs,
2416 }

Callers 2

getQueryFunction · 0.85
parseDirectiveFunction · 0.85

Calls 7

collectNameFunction · 0.85
validKeyFunction · 0.85
parseLanguageListFunction · 0.85
ItemMethod · 0.80
NextMethod · 0.45
ErrorfMethod · 0.45
PeekMethod · 0.45

Tested by

no test coverage detected