Commit 2249e14
endtoend: run sqlc fmt over the sqlite testdata queries (#4582)
* fmt: keep the author's operator, join and parameter spellings; lowercase coalesce
SQLite gives several constructs more than one spelling, and the
formatter was silently picking one: != printed as <> and == as =, a
comma-separated FROM item printed as JOIN, a bare JOIN with no ON
printed as CROSS JOIN — a planner hint in SQLite the author did not
write — and a numbered parameter printed as a bare ?, which is worse
than a spelling change: reordered ?N parameters bind by their numbers,
so VALUES (?2, ?1) rewritten to (?, ?) swaps its arguments.
Operators keep pg_query's shape: A_Expr.Name is the operator as the
engine's parser saw it, and since meyer's tree keeps only the operator
kind, the sqlite converter reads the author's spelling back out of the
source between the operands. The compiler already recognizes every
spelling, as it must for MySQL, whose canonical != flows through the
same lists.
Joins that SQLite treats distinctly become distinct: JoinType gains
JoinTypeCross (the planner hint) and JoinTypeComma (its own syntax)
beyond the libpg_query set, the sqlite converter maps to them, and the
printer spells each as itself — which retires the printer's guess that
an inner join with no condition must be a CROSS JOIN. PostgreSQL,
whose grammar really does mean CROSS JOIN by that shape (a bare JOIN
without ON is a syntax error there), now says so in its converter.
Redundant spellings still normalize: INNER JOIN prints as JOIN and
LEFT OUTER JOIN as LEFT JOIN, which mean exactly the same thing.
Parameters use the numbering the node already records: Dialect.Param
gains a numbered flag, ParamRef passes its Dollar field, and sqlite
prints ?N for a numbered parameter and ? for a bare one.
Compound selects gain the seam boundary the clauses already had: an
author who broke the line around UNION, INTERSECT or EXCEPT keeps the
operator on its own line, and a one-line compound stays on one line.
Statements sqlc has no node for (PRAGMA and friends) stay in the file:
ParseFile kept them out of its statement list, so the formatter never
saw their extents — it deleted the statements and pulled the name
annotations of their neighbours inside the preceding query. They now
stay in the list as TODOs, which render as nothing and fall back
verbatim; Parse filters them for the compiler, whose skip behavior is
unchanged. The file-level belt also refuses any result that changes
the file's statement count, so nothing of this class can slip through
again.
The ON CONFLICT DO UPDATE SET list also gains the boundaries the
UPDATE statement's own SET list has: an author who broke the
assignments keeps one per line, with the conflict clause's WHERE at
clause level, and a one-line upsert stays on one line.
COALESCE also drops to lower case: it printed upper-case only because
sqlc special-cases it into a dedicated node for nullability inference
whose Format hardcoded the spelling, while every other function call
prints through FuncCall with its identifier folded lower. The fmt
endtoend case pins all of it.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MTvpHqNMadH12pTtsgUq2
* endtoend: run sqlc fmt over the sqlite testdata queries
Format every sqlite query file in the end-to-end corpus with the new
formatter and regenerate the affected goldens (the generated code embeds
the query text). The fmt case's own input stays unformatted — it is the
formatter's fixture — and nine files are left as written because they
only parse after the compiler's preprocessing (sqlc.arg/narg/slice/
embed, @nAmed parameters).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MTvpHqNMadH12pTtsgUq2
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f9b7b21 commit 2249e14
115 files changed
Lines changed: 774 additions & 619 deletions
File tree
- internal
- cmd
- compiler
- endtoend/testdata
- between_args/sqlite
- go
- builtins/sqlite
- go
- queries
- case_sensitive/sqlite
- go
- coalesce_as/sqlite
- go
- coalesce/sqlite
- go
- column_as/sqlite
- go
- comparisons/sqlite
- count_star/sqlite
- go
- datatype/sqlite/sql
- ddl_alter_table_add_column/sqlite
- go
- ddl_alter_table_case_sensitivity/sqlite
- go
- ddl_alter_table_drop_column/sqlite
- go
- ddl_alter_table_rename_column/sqlite
- go
- ddl_alter_table_rename/sqlite
- go
- experiment_coreanalyzer/sqlite
- go
- fmt/sqlite
- full_outer_join/sqlite
- go
- func_call_cast/sqlite
- go
- func_match_types/sqlite
- go
- inflection/sqlite
- insert_default_values/sqlite
- insert_select/sqlite
- go
- insert_values/sqlite
- invalid_group_by_reference/sqlite
- invalid_table_alias/sqlite
- join_alias/sqlite
- go
- join_left_same_table/sqlite
- go
- join_left/sqlite
- go
- join_where_clause/sqlite
- jsonb/sqlite
- go
- multibyte_comment/sqlite
- go
- quoted_colname/sqlite
- go
- returning/sqlite
- go
- select_exists/sqlite
- go
- select_in_and/sqlite
- go
- select_limit/sqlite
- go
- select_nested_count/sqlite
- go
- select_not_exists/sqlite
- go
- select_star/sqlite
- go
- select_union/sqlite
- go
- single_param_conflict/sqlite
- go
- sqlite_skip_todo
- db
- sqlite_table_options/sqlite
- go
- star_expansion_core/sqlite
- go
- star_expansion/sqlite
- go
- table_function/sqlite
- go
- table_name_case_sensitivity/sqlite
- go
- untyped_columns/sqlite/stdlib
- db
- upsert/sqlite
- go
- virtual_table/sqlite
- go
- where_collate/sqlite
- go
- engine
- clickhouse
- dolphin
- postgresql
- sqlite
- sql
- ast
- format
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
192 | | - | |
| 191 | + | |
| 192 | + | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
196 | | - | |
| 195 | + | |
| 196 | + | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
453 | 453 | | |
454 | 454 | | |
455 | 455 | | |
456 | | - | |
| 456 | + | |
457 | 457 | | |
458 | 458 | | |
459 | 459 | | |
| |||
Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments