apache / apache/datafusion-sqlparser-rs
Why custom Dialect doesn't work properly
- Langage dominant
- Rust
- Étoiles
- 3.5k
- Forks
- 772
- Merge moyen
- 4 j 9 h
- PR mergées (30 j)
- 17
Description
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:**
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par Parser::parse_sql et le trait Dialect, puis comparez l’implémentation personnalisée avec HiveDialect à l’aide de la reproduction test_ast fournie pour SELECT * from 1_a. Suivez la manière dont la gestion du début des identifiants est appliquée et confirmez le comportement d’analyse attendu ; le travail est terminé lorsque la reproduction est expliquée ou que le comportement du parser est corrigé avec un test de régression.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- rust, sql
- Domaine
- compilers, databases
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100