apache / apache/datafusion-sqlparser-rs

Why custom Dialect doesn't work properly

未关闭
#1,186 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
3.5k
派生
772
平均合并
4 天 9 小时
30 天内合并 PR
17

描述

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

贡献指南

这个仓库没有索引到贡献指南

调研方向

从 Parser::parse_sql 和 Dialect trait 开始,然后使用为 SELECT * from 1_a 提供的 test_ast reproduction,将自定义实现与 HiveDialect 进行比较。跟踪标识符起始处理的应用方式,并确认预期的解析行为;完成的标准是解释清楚 reproduction,或通过 regression test 修正 parser 行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
rust, sql
领域
compilers, databases
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。