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 摘要。