Skip to content

feat(semantic): accept Cloud SQL sources, with the dialect read from Knowledge Catalog - #539

Merged
merr1988 merged 1 commit into
mainfrom
feat/sources/cloudsql
Oct 22, 2026
Merged

merr1988 merged 1 commit into
mainfrom
feat/sources/cloudsql

Conversation

@merr1988

@merr1988 merr1988 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Part 5 of b/573288219. A Cloud SQL table or view can be a source, written as its resource name (with or without //):

cloudsql.googleapis.com/projects/<p>/locations/<l>/instances/<i>/databases/<db>/tables/<t>              # MySQL
cloudsql.googleapis.com/projects/<p>/locations/<l>/instances/<i>/databases/<db>/schemas/<s>/tables/<t>  # PostgreSQL, SQL Server

The name can't tell PostgreSQL from SQL Server, so kcmd reads the dialect from the table's entry in @cloudsql
(lookupEntry, entry id = resource name): cloudsql-mysql-table → MYSQL, cloudsql-postgresql-table →
POSTGRES, cloudsql-sqlserver-table → SQLSERVER, and each matching -view type gives the same dialect.

Important

No lookup, no dialect. Code that loads a model without the looked-up dialects gets none for these sources, and
every expression text counts. The commands always look up.

  • When: push, kcmd profiles (incl. --print-store) and skills-generate look each Cloud SQL table up once,
    before anything loads, and pass the dialects to every load. No Cloud SQL resource names, no call.
  • Missing entry: Dataplex answers 403 for "missing", "no access", a misspelled name, the wrong region or a project
    number, so the error says to turn on Dataplex integration for the instance (with the gcloud sql instances patch
    command), check access, or check the name, and the command stops.
  • Plumbing: LoadOptions.cloudSqlDialects → Entity.sourceDialect (set by the loader and by a profile's
    rebinding) → sourcesDialect. Never written to a model file or the catalog.
  • One-database rule: a MySQL or SQL Server table's database is its instance, since one query reaches every
    database on it (a MySQL name keys the same as cloudsql_mysql:); a PostgreSQL table is in its database.

Verified live with the real kcmd profiles: MySQL, PostgreSQL and SQL Server tables read MYSQL, POSTGRES and
SQLSERVER, and a missing table stopped the command. Notes: the catalog syncs about once a day; a SQL Server Express
database needs AUTO_CLOSE OFF to sync; entries outlive a deleted instance until the next sync.

Limitations: cloudsql_postgresql: and the resource name of the same database count as two databases (catalog
names go away in b/573772860); kcmd trusts the catalog, so a stale entry gives a stale dialect; no
cloudsql_sqlserver: catalog name.

Testing: tsc clean; semantic 1866 → 1883, tool 363 → 370, others unchanged (on main at f024085). Each
place that carries the dialect fails a test when removed: push applying a profile, the report's legacy-wrapper load,
and a vanilla model's GOOGLE-block profile included.

Bug: b/573288219

@feixufeixu feixufeixu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, since the required comments are small. Please apply them before you merge.

Comment thread toolbox/mdcode/src/tool/commands.ts
Comment thread toolbox/mdcode/src/libts/semantic/cloudsql_dialect.ts
Comment thread toolbox/mdcode/src/libts/semantic/resolve_profiles.ts Outdated
Comment thread toolbox/mdcode/src/tool/commands.ts
Comment thread toolbox/mdcode/src/libts/semantic/cloudsql_dialect.ts Outdated
Comment thread toolbox/mdcode/tests/tool/profiles.test.ts
Comment thread toolbox/mdcode/src/libts/semantic/cloudsql_dialect.ts Outdated
Comment thread toolbox/mdcode/src/libts/semantic/runtime/runtime.ts Outdated
Comment thread toolbox/mdcode/src/libts/semantic/cloudsql_dialect.ts Outdated
@merr1988
merr1988 force-pushed the feat/sources/cloudsql branch from 5a68c7c to c645e63 Compare October 21, 2026 23:16
…Knowledge Catalog

Part 5 of b/573288219. A Cloud SQL table or view can be a source, written as
its GCP resource name: .../instances/<i>/databases/<db>/tables/<t> for MySQL,
or .../databases/<db>/schemas/<s>/tables/<t> for PostgreSQL and SQL Server.
The name cannot tell PostgreSQL from SQL Server, so kcmd reads the dialect
from the table's entry in the @cloudsql entry group: cloudsql-mysql-table
gives MYSQL, cloudsql-postgresql-table POSTGRES and cloudsql-sqlserver-table
SQLSERVER, and each matching -view type gives the same dialect.

Without a lookup, a Cloud SQL resource name implies no dialect. The commands
always look up; code that loads a model without the looked-up dialects gets
none for these sources, and every expression text counts.

- cloudsql_dialect.ts collects the Cloud SQL resource names in the model and
  profile files and looks each table up once, in parallel, with lookupEntry.
  Dataplex answers 403 for a missing entry, a name it cannot read and a
  misspelled one alike, so the error says to turn on Dataplex integration for
  the instance, check access, or check the name.
- push, kcmd profiles, profiles --print-store and skills-generate look them
  up before anything loads, and stop on an entry they cannot read. A model
  with no such source makes no call.
- LoadOptions.cloudSqlDialects carries the dialects. The loader and a
  profile's rebinding record them on the entity, sourcesDialect uses them,
  and profileForDocument and the completeness check take them. The recorded
  dialect is never written back.
- databaseOf accepts both shapes. For the one-database rule a MySQL or SQL
  Server table's database is its instance, since one query reaches every
  database on it, and a PostgreSQL table is in its database.
- profiles.md and reference.md document the forms, the entry types, the
  Dataplex requirement and that kcmd profiles makes the lookup.

Bug: b/573288219
@merr1988
merr1988 force-pushed the feat/sources/cloudsql branch from c645e63 to 37f2cb6 Compare October 21, 2026 23:24
@merr1988
merr1988 merged commit bb70def into main Oct 22, 2026
7 checks 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