Repository navigation
Conversation
Auto-generated primary keys avoid write hotspots in GoogleSQL using bit_reversed_positive sequences with GET_NEXT_SEQUENCE_VALUE defaults. Add spanner_create_sequence creating Seq and inserting Customers.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new script and corresponding tests to create a GoogleSQL bit-reversed sequence and insert customer records in Google Cloud Spanner. The review feedback points out a dependency issue in the live test cleanup where dropping the sequence before dropping the referencing table will result in a Spanner error; the table must be dropped first.
| drop_sequence.drop_sequence( | ||
| conftest.LIVE_PROJECT_ID, | ||
| conftest.LIVE_INSTANCE_ID, | ||
| conftest.LIVE_DATABASE_ID, | ||
| ) | ||
| admin.update_database_ddl( | ||
| request={ | ||
| "database": db_path, | ||
| "statements": ["DROP TABLE IF EXISTS Customers"], | ||
| } | ||
| ).result(timeout=240) |
There was a problem hiding this comment.
In Google Cloud Spanner, a sequence cannot be dropped if it is still referenced by a table's column default value (such as CustomerId INT64 DEFAULT (GET_NEXT_SEQUENCE_VALUE(SEQUENCE Seq))). Calling drop_sequence.drop_sequence before dropping the Customers table will result in a dependency error and fail the test cleanup. The table must be dropped first.
| drop_sequence.drop_sequence( | |
| conftest.LIVE_PROJECT_ID, | |
| conftest.LIVE_INSTANCE_ID, | |
| conftest.LIVE_DATABASE_ID, | |
| ) | |
| admin.update_database_ddl( | |
| request={ | |
| "database": db_path, | |
| "statements": ["DROP TABLE IF EXISTS Customers"], | |
| } | |
| ).result(timeout=240) | |
| admin.update_database_ddl( | |
| request={ | |
| "database": db_path, | |
| "statements": ["DROP TABLE IF EXISTS Customers"], | |
| } | |
| ).result(timeout=240) | |
| drop_sequence.drop_sequence( | |
| conftest.LIVE_PROJECT_ID, | |
| conftest.LIVE_INSTANCE_ID, | |
| conftest.LIVE_DATABASE_ID, | |
| ) |
There was a problem hiding this comment.
Thanks! The cleanup works in this order because the drop-sequence sample first removes the column default (ALTER TABLE Customers ALTER COLUMN CustomerId DROP DEFAULT) and then drops the sequence, so the table no longer references it.
Problem: multi-line SQL and DDL statements were written as adjacent string fragments. That style is easy to get wrong (a missing trailing space joins two SQL tokens) and is harder to read than the statement itself, and the samples in this set mixed it with triple-quoted SQL. Solution: write each multi-line statement as a single triple-quoted string, matching the layout already used by the other samples. Only whitespace between SQL tokens changes; the statements are otherwise identical. Files updated: - spanner/database_admin/src/spanner_database_admin/create_sequence.py
Description
Adds
spanner_create_sequencecreating a GoogleSQLbit_reversed_positivesequence and inserting rows viaTHEN RETURN.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions