google / google/google-sql-syntax-ts

Formatting of CTEs

Đang mở
#2 2 bình luận 4 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
10
Fork
4
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

The issue provides image examples of poorly indented CTEs and comparisons with SQLfluff and JetBrains formatters, but names no repository files or tests. Start by locating the SQL formatter's handling of Common Table Expressions and reproduce the reported BigQuery/Dataform case; done means nested CTEs have clear indentation and line breaks, with regression coverage for the formatting behavior.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
sql, typescript
Lĩnh vực
databases, tooling
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.