apache / apache/datafusion-sqlparser-rs

Format for Value renders incorrect escaping of quote characters in BigQuery

未關閉
#1,695 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Rust
星號
3.5k
分支
772
平均合併
4 天 9 小時
30 天內合併 PR
17

描述

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

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

從 impl fmt::Display for EscapeQuotedString 以及 tests/sqlparser_bigquery.rs 中失敗的案例開始。執行或新增 test_quote_escape,以比較兩個有效 BigQuery 字串的格式化輸出,接著讓格式化能夠感知方言,使兩種情況都保留有效的跳脫。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
rust, sql
領域
compilers, databases
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。