apache / apache/datafusion-sqlparser-rs

Parser fails when using alias named "TOP" in SELECT statement

Open
#2,046 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
3.5k
Forks
772
Avg merge
4d 9h
Merged PRs (30d)
17

Description

Reproducer: Using datafusion-cli https://github.com/apache/datafusion/tree/main/datafusion-cli compiled from hash 5bbdb7eb1

```
> WITH t AS (SELECT 1 AS val) SELECT tt.val FROM t AS tt;
+-----+
| val |
+-----+
| 1 |
+-----+
1 row(s) fetched.
Elapsed 0.050 seconds.

> WITH t AS (SELECT 1 AS val) SELECT top.val FROM t AS top; 🤔 Invalid statement: SQL error: ParserError("Expected: literal int, found: . at Line: 1, Column: 39")
```

Found by SQLStorm https://github.com/apache/datafusion/issues/17698

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with datafusion-cli built from hash 5bbdb7eb1, comparing the working alias tt with the failing alias top. Trace the SQL parser's handling of TOP in SELECT aliases and verify that the query using top.val parses and returns the expected row.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.