apache / apache/datafusion-sqlparser-rs

ClickHouse: Parsing error for WITH statement using scalar expressions

Offen
#2,221 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
3.5k
Forks
772
Ø Merge
4 T. 9 Std.
Gemergte PRs (30 T.)
17

Beschreibung

### Describe the bug
The ClickHouseDialect parser fails to parse valid ClickHouse syntax when WITH clause is used declaring [scalar expressions](https://clickhouse.com/docs/sql-reference/statements/select/with#common-scalar-expressions).

### To Reproduce
```
use sqlparser::dialect::ClickHouseDialect;
use sqlparser::parser::Parser;

fn main() {
let sql = r#"
WITH 42 AS answer
SELECT answer FROM table
"#;

let dialect = ClickHouseDialect {};
let result = Parser::parse_sql(&dialect, sql);
println!("{:?}", result);
}
```
**Error:**
Err(ParserError("Expected: identifier, found: 42 at Line: 2, Column: 14"))

### Expected behavior tested in ClickHouse 26.1.2.11
The parser using ClickHouseDialect should accept the clause as ClickHouse does support it:
`WITH 42 AS answer SELECT answer FROM table`

### Additional context
The syntax from the [ClickHouse documentation](https://clickhouse.com/docs/sql-reference/statements/select/with#common-scalar-expressions-syntax) for this clause is: `WITH AS `
sqlparser version: 0.61

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Start with ClickHouseDialect and reproduce the supplied Parser::parse_sql example for `WITH 42 AS answer SELECT answer FROM table`. Trace how the ClickHouse WITH clause is parsed, then verify that the parser accepts scalar expressions followed by an alias without regressing existing WITH handling.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
clickhouse, rust, sql
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.