apache / apache/datafusion-sqlparser-rs
tokenizer is not case-sensitive for keyword determination
- Dominant language
- Rust
- Stars
- 3.5k
- Forks
- 772
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 17
Description
Consider the following valid SQL statement:
`UPDATE machine_boards21
SET type = 'hybrid', model = 'LX21'
WHERE id = 'machine1';`
tokenizing produces the following output:
`Word(Word { value: "UPDATE", quote_style: None, keyword: UPDATE }), Whitespace(Space), Word(Word { value: "machine_boards21", quote_style: None, keyword: NoKeyword }), Whitespace(Newline), Word(Word { value: "SET", quote_style: None, keyword: SET }), Whitespace(Space), Word(Word { value: "type", quote_style: None, keyword: TYPE }), Whitespace(Space), Eq, Whitespace(Space), SingleQuotedString("hybrid"), Comma, Whitespace(Space), Word(Word { value: "model", quote_style: None, keyword: NoKeyword }), Whitespace(Space), Eq, Whitespace(Space), SingleQuotedString("LG"), Whitespace(Newline), Word(Word { value: "WHERE", quote_style: None, keyword: WHERE }), Whitespace(Space), Word(Word { value: "id", quote_style: None, keyword: NoKeyword }), Whitespace(Space), Eq, Whitespace(Space), SingleQuotedString("machine1"), SemiColon]`
notice how the 'type' token was interpreted: `Word(Word { value: "type", quote_style: None, keyword: TYPE })`
keyword TYPE... This causes an issue in `parse_assignments()` when `parse_identifiers_non_keywords()` is called
The error ultimately thrown by `calling parse_statement()` on this statement is as follows:
`ParserError("Expected =, found: type")`
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the SQL statement from the issue and inspect parse_assignments(), especially its call to parse_identifiers_non_keywords(). Trace how the tokenizer assigns keyword TYPE to the unquoted type token; done means the statement parses successfully without treating that identifier as a keyword.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- compilers, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100