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
分支
774
平均合併
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 摘要。