ClickHouse / ClickHouse/ClickHouse
clickhouse-format: add --align-column-types option for CREATE TABLE column lists
- Dominant language
- C++
- Stars
- 49.9k
- Forks
- 9k
- Avg merge
- 21h 32m
- Merged PRs (30d)
- 515
Description
## Use case
When writing `CREATE TABLE` DDL by hand, it is common practice to align type declarations so all type tokens start at the same column:
```sql
CREATE TABLE bookings
(
`booking_key` UUID,
`customer_booking_number` String,
`gross_weight` String,
`has_64` Bool,
`timestamp` DateTime
)
ENGINE = ReplacingMergeTree
ORDER BY booking_key
```
This makes schemas significantly easier to scan and review, especially for tables with many columns of varying name lengths.
Currently `clickhouse-format` strips this alignment and produces a single space between every column name and its type:
```sql
CREATE TABLE bookings
(
`booking_key` UUID,
`customer_booking_number` String,
`gross_weight` String,
`has_64` Bool,
`timestamp` DateTime
)
ENGINE = ReplacingMergeTree
ORDER BY booking_key
```
There is no way to round-trip a hand-formatted schema through `clickhouse-format` without losing the alignment. Teams that want consistent formatting via `clickhouse-format` must either give up type alignment or maintain an external post-processing step.
## Describe the solution you'd like
A new `--align-column-types` flag for `clickhouse-format` that pads the gap between each backtick-quoted column name and its type declaration so all type tokens in a `CREATE TABLE` block start at the same column position (longest column name + 2 spaces).
The flag would be opt-in so existing behaviour is unchanged by default.
A ready implementation is available in PR #107939.
## Describe alternatives you've considered
Post-processing `clickhouse-format` output with an external script (e.g. a small Python script that scans `CREATE TABLE` blocks and pads column names). This works but adds a maintenance burden and breaks the "single tool" workflow that `clickhouse-format` is meant to provide.
Contributor guide
Research direction
Start at the `clickhouse-format` entry point and read how its formatting options are handled. The issue names no files or tests, so locate relevant coverage for `CREATE TABLE` column lists. Done means the opt-in `--align-column-types` flag aligns type tokens while leaving default formatting unchanged; the issue says a ready implementation is available in PR #107939.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100