apache / apache/datafusion-sqlparser-rs

The field name in SQL cannot be the same as the keyword name

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

描述

test SQL:

```text
UPDATE tag_group SET name=?, updated_time=?, app=?, app_name=?, is_preset=?, is_default=?, classification=?, sort=?, can_edit=?, can_delete=?, can_add_child=?, can_add_partner=?, can_add_tag=? WHERE id=?
```

```text
update attacker set update_time=$1, attacker_country_name=$2, attacker_desc=$3, attacker_ioc_id=$4, attacker_label=$5, attacker_name=$6, attacker_skill_level=$7, attacker_type=$8, event_diamond_id=$9, incident_id=$10, value=$11 where attacker_id=$12
```

result:
```text
called `Result::unwrap()` on an `Err` value: ParserError("Expected =, found: value")
thread 'interceptor::pg::tests::test_sql' panicked at 'called `Result::unwrap()` on an `Err` value: ParserError("Expected =, found: value")', src/interceptor/pg.rs:719:42
stack backtrace:
```

I think the reason for this mistake is that:
```rust
pub fn parse_assignment(&mut self) -> Result {
let id = self.parse_identifiers_non_keywords()?;
println!("id : {:?}", id);

self.expect_token(&Token::Eq)?;
let value = self.parse_expr()?;

println!("value : {:?}", value.to_string());
Ok(Assignment { id, value })
}
```
```text
word: NoKeyword
id : [Ident { value: "update_time", quote_style: None }]
value : "$1"
word: NoKeyword
id : [Ident { value: "attacker_country_name", quote_style: None }]
value : "$2"
word: NoKeyword
id : [Ident { value: "attacker_desc", quote_style: None }]
value : "$3"
word: NoKeyword
id : [Ident { value: "attacker_ioc_id", quote_style: None }]
value : "$4"
word: NoKeyword
id : [Ident { value: "attacker_label", quote_style: None }]
value : "$5"
word: NoKeyword
id : [Ident { value: "attacker_name", quote_style: None }]
value : "$6"
word: NoKeyword
id : [Ident { value: "attacker_skill_level", quote_style: None }]
value : "$7"
word: NoKeyword
id : [Ident { value: "attacker_type", quote_style: None }]
value : "$8"
word: NoKeyword
id : [Ident { value: "event_diamond_id", quote_style: None }]
value : "$9"
word: NoKeyword
id : [Ident { value: "incident_id", quote_style: None }]
value : "$10"
word: VALUE
id : []
```

expected:

The parameter type after set should be Nokeywork

贡献指南

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

调研方向

从 src/interceptor/pg.rs 中的 parse_assignment 开始,并运行报告中所示的 interceptor::pg::tests::test_sql 测试用例。重现这些 UPDATE 语句,尤其是使用 value 的赋值,并跟踪解析器如何将 SET 后的该单词分类。完成的标准是这些示例能够在不出现报告中的 ParserError 的情况下完成解析,并且涵盖预期的类关键字字段行为。

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

评估

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

把新 issue 发到你的邮箱

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