Skip to content

Commit e15c21d

Browse files
feat(sqlalchemy-spanner): export MAX_SIZE constant (#17922)
Promoting _max_size to public MAX_SIZE (and dialect.max_size) allows cross-dialect applications to inspect Spanner's STRING(MAX) limit through the public API. It eliminates private symbol imports while preserving full backward compatibility for existing code.
1 parent 6431932 commit e15c21d

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

packages/sqlalchemy-spanner/google/cloud/sqlalchemy_spanner/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from .sqlalchemy_spanner import SpannerDialect
15+
from .sqlalchemy_spanner import MAX_SIZE, SpannerDialect
1616
from .version import __version__
1717

18-
__all__ = (SpannerDialect, __version__)
18+
__all__ = (
19+
"MAX_SIZE",
20+
"SpannerDialect",
21+
"__version__",
22+
)

packages/sqlalchemy-spanner/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ def process(value):
159159
selectable.CompoundSelect.INTERSECT_ALL: "INTERSECT ALL",
160160
}
161161

162-
_max_size = 2621440
162+
#: Maximum allowable character/byte length for Cloud Spanner STRING(MAX) and
163+
#: BYTES(MAX) DDL data types (2.5 MiB = 2,621,440 bytes).
164+
MAX_SIZE = 2621440
165+
_max_size = MAX_SIZE
163166

164167

165168
def int_from_size(size_str):
@@ -171,7 +174,7 @@ def int_from_size(size_str):
171174
Returns:
172175
int: The column length value.
173176
"""
174-
return _max_size if size_str == "MAX" else int(size_str)
177+
return MAX_SIZE if size_str == "MAX" else int(size_str)
175178

176179

177180
def engine_to_connection(function):
@@ -848,6 +851,7 @@ class SpannerDialect(DefaultDialect):
848851
paramstyle = "format"
849852
encoding = "utf-8"
850853
max_identifier_length = 256
854+
max_size = MAX_SIZE
851855
_legacy_binary_type_literal_encoding = "utf-8"
852856
_default_isolation_level = "SERIALIZABLE"
853857

packages/sqlalchemy-spanner/tests/unit/test_dialect.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,17 @@ def test_get_multi_indexes_handles_null_column_orderings_array(self):
8484
assert ("public", "my_table") in res
8585
index_info = res[("public", "my_table")][0]
8686
eq_(index_info["column_sorting"], {})
87+
88+
def test_max_size_exported(self):
89+
"""Test MAX_SIZE export and int_from_size helper behavior."""
90+
from google.cloud.sqlalchemy_spanner import MAX_SIZE
91+
from google.cloud.sqlalchemy_spanner.sqlalchemy_spanner import (
92+
_max_size,
93+
int_from_size,
94+
)
95+
96+
eq_(MAX_SIZE, 2621440)
97+
eq_(_max_size, MAX_SIZE)
98+
eq_(SpannerDialect.max_size, MAX_SIZE)
99+
eq_(int_from_size("MAX"), 2621440)
100+
eq_(int_from_size("100"), 100)

0 commit comments

Comments
 (0)