Skip to content

Add coreanalyzer experiment routing generate through the analysis core - #4544

Open
kyleconroy wants to merge 3 commits into
mainfrom
claude/sqlc-core-analyzer-experiment-djnr70
Open

Add coreanalyzer experiment routing generate through the analysis core#4544
kyleconroy wants to merge 3 commits into
mainfrom
claude/sqlc-core-analyzer-experiment-djnr70

Conversation

@kyleconroy

@kyleconroy kyleconroy commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

SQLCEXPERIMENT=coreanalyzer routes sqlc generate through the core catalog and analyzer — the same path sqlc analyze and the ClickHouse and GoogleSQL engines already use — instead of each engine's own analysis path.

  • New experiment in internal/opts: coreanalyzer (no prefix to disable, case-insensitive). When set, parse() builds each query set's compiler with compiler.WithCoreAnalysis().
  • Experiment wiring: Env.Experiment was parsed from the environment but never reached the compiler — processQuerySets always built empty parser options. It now threads the experiment through.
  • Codegen through the core: a core-mode Result carried a nil catalog, which pluginCatalog would dereference — generate had never run on this path (ClickHouse/GoogleSQL only have parse/analyze cases). catalog_core.go now dumps the core catalog into the legacy catalog shape after the schema is applied, so codegen builds models as usual. Seeded pg_catalog/information_schema relations come along but codegen already skips those schemas.
  • Array fix: codegen renders one [] per ArrayDims, which the core path never set — array columns silently generated as scalars (Tags string instead of Tags []string, no pq.Array scan). Both the catalog dump and core query columns now set ArrayDims: 1 when the core reports an array.

Output through the core matches the legacy path exactly for the covered cases, except SELECT * / RETURNING * stay literal in the emitted SQL: the core takes columns from analysis rather than rewriting the query text.

Also documents the experiment in docs/reference/environment-variables.md, replacing the stale "no experiments are defined" note.

Rebased on main after #4545 removed the analyzerv2 experiment; coreanalyzer is now the only experiment, so the wiring passes Env.Experiment through unscoped.

Testing

  • New end-to-end case internal/endtoend/testdata/experiment_coreanalyzer/ with committed goldens for postgresql (stdlib), sqlite, and mysql, run via exec.json env SQLCEXPERIMENT=coreanalyzer.
  • Experiment parsing cases added to the existing internal/opts tests.
  • Full suite green before the rebase: go test --tags=examples -timeout 20m ./... with PostgreSQL and MySQL live. After the rebase: go build ./..., the opts/compiler package tests, and the three experiment_coreanalyzer replay cases.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ANVHEs41RJbybS3ja9N1SA

Comment thread internal/cmd/process.go Outdated
claude added 3 commits August 7, 2026 04:09
SQLCEXPERIMENT=coreanalyzer builds each query set's compiler with
WithCoreAnalysis, the same path sqlc analyze and the ClickHouse and
GoogleSQL engines already use. The experiment now actually reaches the
compiler: processQuerySets threads it into the parser options, which
were previously always empty.

Generating through the core also needs a catalog for codegen to build
models from, which the core path never carried: its Result held a nil
catalog that pluginCatalog would dereference. The core catalog is now
dumped into the legacy catalog shape after the schema is applied. Array
columns additionally set ArrayDims, which codegen renders a [] per, so
they come out as slices rather than silently losing their array-ness.

An end-to-end case pins the generated output for postgresql, sqlite and
mysql.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ANVHEs41RJbybS3ja9N1SA
@kyleconroy
kyleconroy force-pushed the claude/sqlc-core-analyzer-experiment-djnr70 branch from 010a207 to 59c72a0 Compare August 7, 2026 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants