Skip to content

LogQL: empty by () / without () grouping is rejected #989

Closed

Description

@rita7lopes

What

LogQL's empty grouping — by () and without () — is rejected:

_, err := logql_parser.Parse(`max by () (count_over_time({app="x"}[5m]))`)
// 1:5: unexpected token "by" (expected "(" LRAOrUnwrap ")" ByOrWithout? Comparison?)

_, err = logql_parser.Parse(`sum without () (rate({app="x"}[5m]))`)
// 1:5: unexpected token "without" (expected "(" LRAOrUnwrap ")" ByOrWithout? Comparison?)

Non-empty grouping works: max by (app) (count_over_time({app="x"}[5m])) parses fine. So the gap is specifically the empty label list.

Both forms are valid LogQL. Upstream Loki, pkg/logql/syntax/syntax.y:522-523:

| BY OPEN_PARENTHESIS CLOSE_PARENTHESIS      { $$ = &Grouping{ Without: false, Groups: nil } }
| WITHOUT OPEN_PARENTHESIS CLOSE_PARENTHESIS { $$ = &Grouping{ Without: true,  Groups: nil } }

Empty grouping is how you aggregate away every label — semantically distinct from omitting the clause, and Grafana emits it.

Scope

reader/logql/logql_parser grammar: allow an empty label list in ByOrWithout. The transpiler then needs to treat empty by () as "group by nothing" rather than "no grouping" — worth checking that distinction survives into the SQL.

Credit

Found via @tsouza's parser-pin work in #925. The PR pinned max by () (...) as a case that must fail; checking it against the Loki grammar showed it should parse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions