apache / apache/datafusion-sqlparser-rs

Format for Value renders incorrect escaping of quote characters in BigQuery

Ouverte
#1,695 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub
Langage dominant
Rust
Étoiles
3.5k
Forks
772
Merge moyen
4 j 9 h
PR mergées (30 j)
17

Description

`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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez par impl fmt::Display for EscapeQuotedString et les cas en échec dans tests/sqlparser_bigquery.rs. Exécutez ou ajoutez test_quote_escape pour comparer la sortie formatée des deux chaînes BigQuery valides, puis rendez le formatage sensible au dialecte afin que les deux cas conservent un échappement valide.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
rust, sql
Domaine
compilers, databases
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.