apache / apache/datafusion-sqlparser-rs
A bracket-quoted identifier containing `]]` round-trips to SQL that fails to reparse
- Linguagem predominante
- Rust
- Estrelas
- 3.5k
- Forks
- 772
- Merge médio
- 4d 9h
- PRs com merge (30d)
- 17
Descrição
```rust
use sqlparser::dialect::MsSqlDialect;
use sqlparser::parser::Parser;
fn main() {
let sql = "SELECT [a]]b]";
let ast = Parser::parse_sql(&MsSqlDialect {}, sql).unwrap();
let printed = ast[0].to_string();
println!("input: {}", sql);
println!("printed: {}", printed);
let reparsed = Parser::parse_sql(&MsSqlDialect {}, &printed);
println!("reparsed: {:?}", reparsed);
}
```
```
input: SELECT [a]]b]
printed: SELECT [a]b]
reparsed: Err(ParserError("Expected: end of statement, found: ] at Line: 1, Column: 12"))
```
`[a]]b]` is a bracket-quoted identifier whose value is `a]b` (the tokenizer folds the doubled `]]` into a literal `]`). Displaying the parsed AST back to SQL writes `[a]b]` instead, and that string does not parse as the same identifier: it parses as `a` followed by leftover tokens `]b]`.
Tested on sqlparser 0.62.0.
BTW, this bug was found using [hegel](https://crates.io/crates/hegeltest). Happy to contribute the tests if you're interested.
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Reproduza o problema com o exemplo em Rust usando MsSqlDialect, Parser::parse_sql e AST to_string. Inspecione como o tokenizer lida com colchetes duplicados e como o identificador analisado é exibido; em seguida, adicione um teste de regressão de round-trip mostrando que [a]]b] é analisado novamente como o identificador a]b e execute a suíte de testes relevante.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- rust
- Domínio
- databases
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Pouca atividade
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 68/100