apache / apache/datafusion-sqlparser-rs

Format for Value renders incorrect escaping of quote characters in BigQuery

Aberta
#1,695 1 comentário 1 reação 0 responsáveis Ver no GitHub
Linguagem predominante
Rust
Estrelas
3.5k
Forks
772
Merge médio
4d 9h
PRs com merge (30d)
17

Descrição

`impl fmt::Display for EscapeQuotedString` (which is used when formatting a Value expr) uses double quote character escaping (like `''` or `""`) which is a syntax error in BigQuery.

This was also reported in PRQL: https://github.com/PRQL/prql/issues/5099

To fix this, I think we need to make this method aware of the dialect. And potentially add a new supports rule (like supports_backslash_escaping?) If someone could chime in on the approach I can take a stab at it.

Here is a failing test case you can add to tests/sqlparser_bigquery.rs

```rs
#[test]
fn test_quote_escape() {
bigquery().verified_expr(r#"JSON '{"foo":"bar\'s"}'"#); // Wrong output: JSON '{"foo":"bar''s"}'
bigquery().verified_expr(r#"JSON "{\"foo\":\"bar's\"}""#); // Wrong output: JSON "{""foo"":""bar's""}"
}
```

Both of these are valid BigQuery syntax. They get parsed into the AST correctly but get formatted incorrectly.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Comece com impl fmt::Display for EscapeQuotedString e os casos que falham em tests/sqlparser_bigquery.rs. Execute ou adicione test_quote_escape para comparar a saída formatada das duas strings BigQuery válidas e, em seguida, torne a formatação ciente do dialeto para que ambos os casos mantenham um escape válido.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
rust, sql
Domínio
compilers, databases
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.