apache / apache/datafusion-sqlparser-rs
Unexpected failure parsing SQLite CREATE TABLE statement
- 主要言語
- Rust
- スター
- 3.5k
- フォーク
- 772
- 平均マージ
- 4日 9時間
- マージ済み PR(30日)
- 17
説明
When parsing the following statement with the SQLite dialect:
```sql
CREATE TABLE '""' (
'id' INT UNSIGNED NOT NULL,
'name' TEXT NOT NULL,
'surname' TEXT NULL,
'zip' INT UNSIGNED NULL
);
```
the result is:
`ParserError("Expected column name or constraint definition, found: 'id'")`
but I expect that this would be correctly parsed as a CREATE TABLE statement with `""` as the table name. From the SQL grammar, the table name in a CREATE TABLE statement appears to be a [local or schema qualified name](https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#local-or-schema-qualified-name). It's not actually clear to me if using single quotes to delimit a table name is valid according to that description of the grammar, but SQLite does accept it. For reference, [here](https://www.sqlite.org/lang_createtable.html) is the SQLite documentation for CREATE TABLE.
This is definitely an uncommon edge case. I found it in the [Standardized corpus for SQLite Database Forensics](https://www.sciencedirect.com/science/article/pii/S1742287618300471) (accessible [here](https://faui1-files.cs.fau.de/public/sqlite-forensic-corpus/)) in sample 01-01. (For context, I'm using that collection as a set of test cases for a personal project I'm working on which uses this library.)
Full repro using sqlparser 0.9.0:
```rust
fn main() {
let statement = "CREATE TABLE '\"\"' (\n\t'id' INT UNSIGNED NOT NULL,\n\t'name' TEXT NOT NULL,\n\t'surname' TEXT NULL,\n\t'zip' INT UNSIGNED NULL\n)";
let dialect = sqlparser::dialect::SQLiteDialect {};
let parsed = sqlparser::parser::Parser::parse_sql(&dialect, statement).unwrap();
}
```
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
Start with the SQLiteDialect and Parser::parse_sql entry points, using the supplied CREATE TABLE statement as the reproduction. Trace how quoted table and column names are parsed, then add coverage showing that this statement is accepted as a CREATE TABLE statement with the expected table name.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- rust, sqlite
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100