Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .sqlalchemy_spanner import SpannerDialect
from .sqlalchemy_spanner import MAX_SIZE, SpannerDialect
from .version import __version__

__all__ = (SpannerDialect, __version__)
__all__ = (
"MAX_SIZE",
"SpannerDialect",
"__version__",
)
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ def process(value):
selectable.CompoundSelect.INTERSECT_ALL: "INTERSECT ALL",
}

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: should we consider renaming this to MAX_STRING_COLUMN_LENGTH? Or is the MAX_SIZE name a standard in SQLAlchemy? If we keep the name MAX_SIZE, can we add a docstring that explains what this max is for?

_max_size = MAX_SIZE


def int_from_size(size_str):
Expand All @@ -162,7 +165,7 @@ def int_from_size(size_str):
Returns:
int: The column length value.
"""
return _max_size if size_str == "MAX" else int(size_str)
return MAX_SIZE if size_str == "MAX" else int(size_str)


def engine_to_connection(function):
Expand Down Expand Up @@ -833,6 +836,7 @@ class SpannerDialect(DefaultDialect):
paramstyle = "format"
encoding = "utf-8"
max_identifier_length = 256
max_size = MAX_SIZE
_legacy_binary_type_literal_encoding = "utf-8"
_default_isolation_level = "SERIALIZABLE"

Expand Down
14 changes: 14 additions & 0 deletions packages/sqlalchemy-spanner/tests/unit/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,17 @@ def test_get_multi_indexes_handles_null_column_orderings_array(self):
assert ("public", "my_table") in res
index_info = res[("public", "my_table")][0]
eq_(index_info["column_sorting"], {})

def test_max_size_exported(self):
"""Test MAX_SIZE export and int_from_size helper behavior."""
from google.cloud.sqlalchemy_spanner import MAX_SIZE
from google.cloud.sqlalchemy_spanner.sqlalchemy_spanner import (
_max_size,
int_from_size,
)

eq_(MAX_SIZE, 2621440)
eq_(_max_size, MAX_SIZE)
eq_(SpannerDialect.max_size, MAX_SIZE)
eq_(int_from_size("MAX"), 2621440)
eq_(int_from_size("100"), 100)
Loading