apache / apache/datafusion-sqlparser-rs

Why custom Dialect doesn't work properly

Aperta
#1,186 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Rust
Stelle
3.5k
Fork
772
Merge medio
4g 9h
PR unite (30g)
17

Descrizione

I have extended a Dialect named MyDialect, and implemented the is_identifier_start method. is_identifier_start allows the identifier to start with a number, but why does my test code report an error? The prompt says that it cannot start with a number, and if I run it with the native HiveDialect, the code No problem again

**My Code:**
```
#[derive(Debug)]
pub struct MyDialect;

impl Dialect for MyDialect {
fn is_delimited_identifier_start(&self, ch: char) -> bool {
(ch == '"') || (ch == '`')
}

fn is_identifier_start(&self, ch: char) -> bool {
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '$'
}

fn is_identifier_part(&self, ch: char) -> bool {
ch.is_ascii_lowercase()
|| ch.is_ascii_uppercase()
|| ch.is_ascii_digit()
|| ch == '_'
|| ch == '$'
|| ch == '{'
|| ch == '}'
}

fn supports_filter_during_aggregation(&self) -> bool {
true
}
}

#[cfg(test)]
mod tests {
use sqlparser::parser::Parser;

#[test]
pub fn test_ast() {
let sql = "SELECT * from 1_a";
let expected_sql = "SELECT * from 1_a"
.replace("\n", "");
let dialect = crate::core::ast::MyDialect {};
let ast = Parser::parse_sql(&dialect, sql).unwrap();
assert_eq!(ast[0].to_string(), expected_sql);
}
}
```

**HIveDialect Code(from sqlparser-rs)**
use crate::dialect::Dialect;

/// A [`Dialect`] for [Hive](https://hive.apache.org/).
```
#[derive(Debug)]
pub struct HiveDialect {}

impl Dialect for HiveDialect {
fn is_delimited_identifier_start(&self, ch: char) -> bool {
(ch == '"') || (ch == '`')
}

fn is_identifier_start(&self, ch: char) -> bool {
ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch.is_ascii_digit() || ch == '$'
}

fn is_identifier_part(&self, ch: char) -> bool {
ch.is_ascii_lowercase()
|| ch.is_ascii_uppercase()
|| ch.is_ascii_digit()
|| ch == '_'
|| ch == '$'
|| ch == '{'
|| ch == '}'
}

fn supports_filter_during_aggregation(&self) -> bool {
true
}
}
```

**Error:**
image

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia da Parser::parse_sql e dal trait Dialect, quindi confronta l’implementazione personalizzata con HiveDialect usando la riproduzione test_ast fornita per SELECT * from 1_a. Traccia il modo in cui viene applicata la gestione dell’inizio degli identificatori e conferma il comportamento di parsing previsto; il lavoro è completato quando la riproduzione è spiegata oppure il comportamento del parser è corretto con un test di regressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
rust, sql
Ambito
compilers, databases
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.