apache / apache/datafusion-sqlparser-rs

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

オープン
#497 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
3.5k
フォーク
772
平均マージ
4日 9時間
マージ済み PR(30日)
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 を短くまとめたダイジェスト。