Skip to content

Add Spanner GoogleSQL corpus and parse its DDL gaps - #1

Merged
kyleconroy merged 3 commits into
mainfrom
claude/sharp-maxwell-vdp4cl
Oct 14, 2026
Merged

kyleconroy merged 3 commits into
mainfrom
claude/sharp-maxwell-vdp4cl

Conversation

@kyleconroy

Copy link
Copy Markdown
Contributor

Summary

Adds a test corpus built from the SQL examples in Cloud Spanner's GoogleSQL docs, and teaches the parser the syntax that corpus showed was missing.

Spanner corpus (cmd/spanner-corpus)

  • Scrapes the copyable GoogleSQL examples from the Spanner reference pages (DDL, DML, query, pipe, procedural, graph, functions) and about 130 guide pages. PostgreSQL tabs, grammar blocks and query-result comments are skipped.
  • Runs each statement through the pinned reference parser (execute_query, with SPANNER_LEGACY_DDL and the graph features enabled). Accepted examples are written as golden cases under parser/testdata/spanner/ (2476 cases); TestParser and next-test now pick them up recursively.
  • Rejected examples are triaged rather than dropped silently:
    • Heuristics drop grammar fragments, examples marked -- Error: and bare graph patterns (-v lists them).
    • Statements the docs list without ; between them are split and retried.
    • Everything else is classified by ID in cmd/spanner-corpus/triage.txt. Spanner-only syntax that the reference parser rejects is written to <page>.spanner.sql; this backlog has 160 statements (GRANT … TO ROLE, change streams, proto bundles, locality groups, identity columns, …). Doc typos are dropped. Untriaged rejects go to <page>.rejected.sql; there are none now.
  • -discover crawls the docs navigation for guide pages that aren't in pages.go yet.
  • The execute_query handling moved into internal/refparse, shared with regenerate-parse. Three bugs fixed along the way:
    • SQL that starts with -- is no longer read as a command-line flag.
    • Errors that execute_query prints to stdout with exit code 0 are now treated as errors.
    • --output_asc_explicitly is passed, matching the test driver's output.

Parser

  • HIDDEN column attribute.
  • CREATE [OR REPLACE] [scope] PROPERTY GRAPH with node and edge element tables: KEY, SOURCE/DESTINATION KEY … REFERENCES, LABEL / DEFAULT LABEL, the PROPERTIES forms, DYNAMIC LABEL/PROPERTIES, and OPTIONS. Also DROP PROPERTY GRAPH.
  • DROP {SEARCH|VECTOR} INDEX and ALTER {SEARCH|VECTOR} INDEX (SET OPTIONS, ADD/DROP COLUMN, ALTER COLUMN SET OPTIONS, REBUILD).

Parse trees and error messages were checked against the reference parser, including about 60 malformed inputs. No parse_todo cases remain.

Test plan

  • go test ./... -timeout 60s passes.
  • go test ./parser -check-parse leaves no todos.
  • go run ./cmd/spanner-corpus regenerates identical output.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UYsqdZSDA9cbKQdQissXaR


Generated by Claude Code

Add cmd/spanner-corpus, which scrapes the SQL examples from Cloud
Spanner's GoogleSQL reference pages (DDL, DML, query, pipe, procedural,
graph and function pages), runs each through the reference parser with
Spanner's language features, and writes accepted examples as golden
cases under parser/testdata/spanner/. Examples the reference rejects
(Spanner-only syntax, doc typos, grammar fragments) are listed in
per-page .rejected.sql files for triage.

The parser tests and next-test now include the Spanner files. 1529 of
1545 cases pass; the 16 remaining todos are HIDDEN columns, PROPERTY
GRAPH DDL and DROP VECTOR INDEX.

Move the execute_query download/run logic into internal/refparse so
regenerate-parse and spanner-corpus share it. Pass "--" before the SQL
(a leading "--" comment was taken as a flag), detect errors printed to
stdout with a zero exit status, and pass --output_asc_explicitly to
match the parser test driver's output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UYsqdZSDA9cbKQdQissXaR
Scrape the GoogleSQL examples from ~130 Spanner guide pages (found with
the new -discover mode) in addition to the reference pages; their
cases go under parser/testdata/spanner/guides/. PostgreSQL tabs are
skipped and query-result comments are stripped (some are closed with a
typo'd "/*" that swallowed the rest of the block).

Rejected examples are now classified instead of dumped:

- Grammar templates, partial clauses, bare graph patterns, "-- Error:"
  examples and similar are recognized by heuristics and dropped.
- Examples that list statements without ";" are split and retried.
- The rest are classified by id in cmd/spanner-corpus/triage.txt as
  spanner (written to <page>.spanner.sql, the Spanner-only syntax
  backlog), typo or fragment. Untriaged rejects go to
  <page>.rejected.sql; there are none now.

2476 cases; the 87 that fail are all PROPERTY GRAPH DDL, HIDDEN columns
or DROP VECTOR INDEX. 160 Spanner-only statements are in the backlog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UYsqdZSDA9cbKQdQissXaR
- HIDDEN column attribute (HiddenColumnAttribute) in column_attributes.
- CREATE [OR REPLACE] [scope] PROPERTY GRAPH with node/edge element
  tables: KEY, SOURCE/DESTINATION KEY ... REFERENCES, LABEL / DEFAULT
  LABEL, NO PROPERTIES / PROPERTIES [ARE] ALL COLUMNS [EXCEPT (...)] /
  PROPERTIES (derived, ...), DYNAMIC LABEL / DYNAMIC PROPERTIES, and
  element and statement OPTIONS. DROP PROPERTY GRAPH as a generic
  DropStatement.
- DROP {SEARCH|VECTOR} INDEX [IF EXISTS] name [ON table].
- ALTER {SEARCH|VECTOR} INDEX with SET OPTIONS, ADD/DROP COLUMN,
  ALTER COLUMN SET OPTIONS and REBUILD actions.

Trees and error messages were checked against the reference parser,
including the error paths. This clears the last Spanner corpus todos;
no parse_todo cases remain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UYsqdZSDA9cbKQdQissXaR
@kyleconroy
kyleconroy merged commit c329d05 into main Oct 14, 2026
1 check passed
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