apache / apache/datafusion-sqlparser-rs
Why custom Dialect doesn't work properly
- Lenguaje dominante
- Rust
- Estrellas
- 3.5k
- Forks
- 772
- Merge medio
- 4 d 9 h
- PR fusionados (30 d)
- 17
Descripción
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:**
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza en Parser::parse_sql y en el trait Dialect, y luego compara la implementación personalizada con HiveDialect usando la reproducción proporcionada de test_ast para SELECT * from 1_a. Traza cómo se aplica el manejo del inicio de identificadores y confirma el comportamiento de parsing esperado; se considera terminado cuando la reproducción está explicada o el comportamiento del parser se ha corregido con una prueba de regresión.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- rust, sql
- Área
- compilers, databases
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 30/100