HogQL parser rejects an alias binding followed by an operator
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 39.9k
- Forks
- 3.4k
- Avg merge
- 6h 51m
- Merged PRs (30d)
- 232
Description
Bug description
The parser accepts expr AS alias and it accepts (expr AS alias) <op> …, but it rejects
expr AS alias <op> … without the parentheses. The alias binds, and then the operator is
treated as a trailing token rather than as an operator applied to the aliased expression.
The failure is a parse error, so it lands before any resolution or type checking.
How to reproduce
Run against master:
from posthog.hogql.parser import parse_select
parse_select("SELECT 1 AS x > 0")
Result:
SyntaxError: trailing tokens after expression: '>' (Gt)
The same shape fails with every operator class tried:
| Query | Result |
|---|---|
SELECT (1 AS x) > 0 |
parses |
SELECT 1 AS x > 0 |
trailing tokens after expression: '>' (Gt) |
SELECT 1 AS x + 1 |
trailing tokens after expression: '+' (Plus) |
SELECT 1 AS x IS NULL |
trailing tokens after expression: 'IS' (Keyword(Is)) |
SELECT 1 AS x BETWEEN 0 AND 2 |
trailing tokens after expression: 'BETWEEN' … |
SELECT if(1 AS x > 0, 2, 3) |
expected ), got Gt |
SELECT sum(1 AS x > 0) FROM events |
expected ), got Gt |
The last two matter most: inside a function call there is no trailing-token position at all,
so the parse fails on the argument list.
Expected
An alias binding should be able to participate in a surrounding expression without
parentheses, as it can in ClickHouse SQL.
Notes
Executed against master today, not inferred. The relevant precedence handling is in
rust/hogql/parser/src/parse/expr.rs (after_bare_alias); the grammar has no
corresponding alias-then-operator production.
Worth confirming the exact ClickHouse-side acceptance boundary before fixing, so the
two parsers are brought into line deliberately rather than by guess.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in rust/hogql/parser/src/parse/expr.rs, especially after_bare_alias, and reproduce the listed queries through posthog.hogql.parser.parse_select. Confirm the exact ClickHouse acceptance boundary, then bring the grammar and precedence handling into line so alias bindings work with surrounding operators without parentheses, including function arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clickhouse, python, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100