Repository navigation
fix(tool/spanner-list-tables): return constraint key columns as separate JSON array elements - #4603
Open
beskvladimir-create wants to merge 4 commits into
Conversation
…ons from unquoted column names
…ate JSON array elements
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the spanner-postgres and spanner-list-tables tools to correctly handle multi-column constraints by introducing a new quoted_column_names_json_list field. This ensures that composite key columns are returned as individual elements in the JSON output. Additionally, a new integration test, runSpannerListTablesConstraintColumnsTest, was added to verify that primary and foreign key constraints with multiple columns are correctly parsed and returned by the tool.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
spanner-list-tablesand the prebuiltspanner-postgreslist_tablesuse one aggregate,constraint_columns_agg_cte.column_names_json_list, both insideconstraint_definitionand as the JSON array ofconstraint_columns/foreign_key_referenced_columns:spanner-list-tables(GoogleSQL and PostgreSQL dialects): the list holds bare names and the joined string is wrapped in one pair of quotes, soPRIMARY KEY (singer_id, album_id)comes back as"constraint_columns":["singer_id,album_id"], and constraints without (referenced) columns get[""]instead of[].spanner-postgreslist_tables: the list holds quoted names, which is right for the arrays but produces"constraint_definition":"PRIMARY KEY ("id")".processRowsin the Spanner source runsjson.Unmarshalon everyobject_detailsvalue, so the detailed output fails withunable to unmarshal JSONfor any table with a primary key.Fix:
constraint_columns_agg_ctenow keeps both a bare list (forconstraint_definition) and a quoted list (for the JSON arrays):spanner-list-tables: newquoted_column_names_json_list, used forconstraint_columnsandforeign_key_referenced_columnswithout the extra surrounding quotes.constraint_definitionis unchanged.spanner-postgres.yaml: new barecolumn_names_list, used in the four places whereconstraint_definitionconcatenates key columns. The arrays are unchanged.Columns, indexes and
simpleoutput are not affected.Testing: I copied the PostgreSQL-dialect string-building expressions (old and new) into psql on PostgreSQL 16.15 with sample key-column rows and parsed the output with a JSON parser: before, the prebuilt output did not parse and the tool output had
["singer_id,album_id"]; after, both give"constraint_columns":["singer_id","album_id"],"foreign_key_referenced_columns":["singer_id"]and[]for constraints without columns. The GoogleSQL statement uses the same pattern and was only checked by reading. I addedrunSpannerListTablesConstraintColumnsTesttoTestSpannerToolEndpoints; it checks the composite primary key(id, target_id)and the foreign key of the existing interleaved edge table. I could not run Spanner or the Go integration tests locally, so the test relies on CI.Security: no new parameters; the tool still binds
table_namesandoutput_formatas query parameters and the change only affects how catalog values are concatenated into the JSON string.PR Checklist
!if this involve a breaking change (not a breaking change)🛠️ Fixes #4602