apache / apache/datafusion-sqlparser-rs
Format for Value renders incorrect escaping of quote characters in BigQuery
- Dominant language
- Rust
- Stars
- 3.5k
- Forks
- 772
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with impl fmt::Display for EscapeQuotedString and the failing cases in tests/sqlparser_bigquery.rs. Run or add test_quote_escape to compare the formatted output for both valid BigQuery strings, then make the formatting dialect-aware so both cases retain valid escaping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- compilers, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100