apache / apache/datafusion-sqlparser-rs

Format for Value renders incorrect escaping of quote characters in BigQuery

Abierto
#1,695 1 comentario 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
3.5k
Forks
772
Merge medio
4 d 9 h
PR fusionados (30 d)
17

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza con impl fmt::Display for EscapeQuotedString y los casos que fallan en tests/sqlparser_bigquery.rs. Ejecuta o añade test_quote_escape para comparar la salida formateada de ambas cadenas BigQuery válidas y, después, haz que el formateo tenga en cuenta el dialecto para que ambos casos conserven un escape válido.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rust, sql
Área
compilers, databases
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.