Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(spanner, sqlalchemy-spanner): fix reflection crashes, add native UUID support, and improve JsonObject#17822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
sakthivelmanii
wants to merge
1
commit into
main
from
fix-sqlalchemy-spanner-reflection-uuid-batch-storing
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31 packages/google-cloud-spanner/google/cloud/spanner_v1/data_types.py
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
23 changes: 23 additions & 0 deletions
23 packages/google-cloud-spanner/tests/unit/test_datatypes.py
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| [run] | ||
| branch = True | ||
| source = | ||
| google/cloud/sqlalchemy_spanner | ||
| [paths] | ||
| source = | ||
| google/cloud/sqlalchemy_spanner | ||
| */site-packages/google/cloud/sqlalchemy_spanner | ||
| [report] | ||
| fail_under = 65 | ||
| show_missing = True | ||
| exclude_lines = | ||
| pragma: NO COVER | ||
| def __repr__ | ||
| raise NotImplementedError | ||
| omit = | ||
| tests/* | ||
| */tests/* |
33 changes: 25 additions & 8 deletions
33 packages/sqlalchemy-spanner/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -120,6 +120,8 @@ def process(value): | ||
| "TIMESTAMP": types.TIMESTAMP, | ||
| "ARRAY": types.ARRAY, | ||
| "JSON": types.JSON, | ||
| "TOKENLIST": types.String, | ||
| "UUID": types.UUID, | ||
| } | ||
| @@ -136,6 +138,7 @@ def process(value): | ||
| types.String: "STRING", | ||
| types.TIME: "TIME", | ||
| types.TIMESTAMP: "TIMESTAMP", | ||
| types.UUID: "UUID", | ||
| types.Integer: "INT64", | ||
| types.NullType: "INT64", | ||
| } | ||
| @@ -426,8 +429,10 @@ def returning_clause(self, stmt, returning_cols, **kw): | ||
| ) | ||
| for c in expression._select_iterables( | ||
| filter( | ||
| lambda col: not col.dialect_options.get("spanner", {}).get( | ||
| "exclude_from_returning", False | ||
| lambda col: ( | ||
| not col.dialect_options.get("spanner", {}).get( | ||
| "exclude_from_returning", False | ||
| ) | ||
| ), | ||
| returning_cols, | ||
| ) | ||
| @@ -709,12 +714,16 @@ def visit_create_index( | ||
| options = index.dialect_options["spanner"] | ||
| if "storing" in options: | ||
| storing = options["storing"] | ||
| storing_columns = [ | ||
| index.table.c[col] if isinstance(col, str) else col | ||
| for col in storing | ||
| ] | ||
| storing_names = [] | ||
| for col in storing: | ||
| if isinstance(col, str): | ||
| storing_names.append(col) | ||
| elif hasattr(col, "name"): | ||
| storing_names.append(col.name) | ||
| else: | ||
| storing_names.append(str(col)) | ||
| text += " STORING (%s)" % ", ".join( | ||
| [self.preparer.quote(c.name) for c in storing_columns] | ||
| [self.preparer.quote(name) for name in storing_names] | ||
| ) | ||
| interleave_in = options.get("interleave_in") | ||
| @@ -814,6 +823,12 @@ def visit_NUMERIC(self, type_, **kw): | ||
| def visit_BIGINT(self, type_, **kw): | ||
| return "INT64" | ||
| def visit_UUID(self, type_, **kw): | ||
| return "UUID" | ||
| def visit_uuid(self, type_, **kw): | ||
| return "UUID" | ||
| def visit_JSON(self, type_, **kw): | ||
| return "JSON" | ||
| @@ -1300,6 +1315,7 @@ def get_multi_indexes( | ||
| {table_type_query} | ||
| {schema_filter_query} | ||
| i.index_type != 'PRIMARY_KEY' | ||
| AND i.index_type != 'SEARCH' | ||
| AND i.spanner_is_managed = FALSE | ||
| GROUP BY i.table_catalog, i.table_schema, i.table_name, | ||
| i.index_name, i.is_unique | ||
| @@ -1324,7 +1340,8 @@ def get_multi_indexes( | ||
| "column_names": row[3], | ||
| "unique": row[4], | ||
| "column_sorting": { | ||
| col: order.lower() for col, order in zip(row[3], row[5]) | ||
| col: (order.lower() if order else None) | ||
| for col, order in zip(row[3], row[5] or []) | ||
| }, | ||
sakthivelmanii marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| "include_columns": include_columns if include_columns else [], | ||
| "dialect_options": dialect_options, | ||
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
83 changes: 83 additions & 0 deletions
83 packages/sqlalchemy-spanner/tests/mockserver_tests/test_dialect_integration.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Copyright 2026 Google LLC All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from google.cloud.spanner_admin_database_v1 import UpdateDatabaseDdlRequest | ||
| from google.cloud.spanner_v1 import ResultSet | ||
| from sqlalchemy import Column, Index, MetaData, Table, Uuid, types | ||
| from sqlalchemy.testing import eq_, is_instance_of | ||
| from tests.mockserver_tests.mock_server_test_base import ( | ||
| MockServerTestBase, | ||
| add_result, | ||
| ) | ||
| class TestDialectIntegration(MockServerTestBase): | ||
| def test_create_table_with_native_uuid(self): | ||
| """Integration test verifying native UUID and TOKENLIST DDL generation.""" | ||
| add_result( | ||
| """SELECT true | ||
| FROM INFORMATION_SCHEMA.TABLES | ||
| WHERE TABLE_SCHEMA="" AND TABLE_NAME="products" | ||
| LIMIT 1 | ||
| """, | ||
| ResultSet(), | ||
| ) | ||
| engine = self.create_engine() | ||
| metadata = MetaData() | ||
| Table( | ||
| "products", | ||
| metadata, | ||
| Column("product_id", Uuid, primary_key=True), | ||
| Column("token_data", types.String()), | ||
| ) | ||
| metadata.create_all(engine) | ||
| requests = self.database_admin_service.requests | ||
| eq_(1, len(requests)) | ||
| is_instance_of(requests[0], UpdateDatabaseDdlRequest) | ||
| statement = requests[0].statements[0] | ||
| assert "product_id UUID NOT NULL" in statement | ||
| def test_create_index_with_storing_clause(self): | ||
| """Integration test verifying DDL generation for indexes with STORING clause.""" | ||
| add_result( | ||
| """SELECT true | ||
| FROM INFORMATION_SCHEMA.TABLES | ||
| WHERE TABLE_SCHEMA="" AND TABLE_NAME="items" | ||
| LIMIT 1 | ||
| """, | ||
| ResultSet(), | ||
| ) | ||
| engine = self.create_engine() | ||
| metadata = MetaData() | ||
| items = Table( | ||
| "items", | ||
| metadata, | ||
| Column("id", Uuid, primary_key=True), | ||
| Column("category", types.String(50)), | ||
| Column("name", types.String(100)), | ||
| Column("description", types.String(500)), | ||
| ) | ||
| Index( | ||
| "ix_items_category", | ||
| items.c.category, | ||
| spanner_storing=["name", "description"], | ||
| ) | ||
| metadata.create_all(engine) | ||
| requests = self.database_admin_service.requests | ||
| eq_(1, len(requests)) | ||
| is_instance_of(requests[0], UpdateDatabaseDdlRequest) | ||
| statements = requests[0].statements | ||
| create_index_statement = [s for s in statements if "CREATE INDEX" in s][0] | ||
| assert "STORING (name, description)" in create_index_statement |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for a nested JsonObject structure? For example a JsonObject containing an array of JsonObject?