google / google/google-sql-syntax-ts

Formatting of CTEs

未关闭
#2 2 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
10
派生
4
PR 合并指标
30 天内没有已合并 PR

描述

Hello,

We use Dataform and BigQuery extensively in our projects. The built-in SQL formatter, which appears to be based on this repository, presents significant challenges in its current form due to how it handles Common Table Expressions (CTEs).

The primary issue is the lack of clear indentation, making it difficult to discern where CTEs begin and end in the formatted SQL. Below are examples that illustrate this problem:

### Example 1: BigQuery/Dataform Formatter
*The image shows a query formatted by the current formatter. Notice the minimal indentation, making it hard to distinguish the boundaries of the CTEs.*
![BigQuery/Dataform Formatter](https://github.com/google/google-sql-syntax-ts/assets/24190330/58aff9d8-df58-4fc7-b165-834b1d3049c4)

### Example 2: SQLfluff Formatter
*The same query formatted with SQLfluff. The CTEs are clearly indented, making it easy to identify where they start and end.*
![SQLfluff Formatter](https://github.com/google/google-sql-syntax-ts/assets/24190330/8a66281f-3669-471b-b3ed-ffb864862a3e)

### Example 3: JetBrains Default Formatter (PyCharm/DataGrip)
*Another example using JetBrains' default formatter. It also clearly shows the structure of CTEs through proper indentation.*
![JetBrains Formatter](https://github.com/google/google-sql-syntax-ts/assets/24190330/3db4ffb8-64d1-480a-9197-36d3eb51b0af)

### Suggestion
To enhance readability and usability, we suggest the following improvements for CTE formatting:
- **Indentation:** Clearly indent each level of CTEs.
- **Line Breaks:** Ensure that each CTE and its constituent SQL statements are well-separated by line breaks.

Implementing these changes would significantly improve the readability of formatted SQL queries, making it easier for developers to work with complex queries involving multiple CTEs.

Thank you for considering this suggestion.

Best regards,
Schnurres

贡献指南

打开贡献指南

调研方向

该 issue 提供了缩进不佳的 CTE 图片示例,以及与 SQLfluff 和 JetBrains 格式化器的比较,但没有指明仓库中的文件或测试。首先定位 SQL 格式化器处理 Common Table Expressions 的位置,并复现所报告的 BigQuery/Dataform 情况;当嵌套 CTE 具有清晰的缩进和换行,并且针对该格式化行为具备回归测试覆盖时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
sql, typescript
领域
databases, tooling
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。