apache / apache/datafusion-sqlparser-rs
The field name in SQL cannot be the same as the keyword name
- Dominant language
- Rust
- Stars
- 3.5k
- Forks
- 772
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 17
Description
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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with parse_assignment in src/interceptor/pg.rs and run the interceptor::pg::tests::test_sql case shown in the report. Reproduce the UPDATE statements, especially the assignment using value, and trace how the parser classifies that word after SET. Done means these examples parse without the reported ParserError and the expected keyword-like field behavior is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100