Skip to content

Commit c71e081

Browse files
SQLAlchemy: TINYINT types didn't reflect properly (databricks#315)
Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent 4bb3c9e commit c71e081

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
# 3.1.0 (TBD)
44

5-
- SQLAlchemy: Added support for table and column comments (thanks @cbornet!)
5+
- SQLAlchemy dialect now supports table and column comments (thanks @cbornet!)
6+
- Fix: SQLAlchemy dialect now correctly reflects TINYINT types (thanks @TimTheinAtTabs!)
67
- Fix: `server_hostname` URIs that included `https://` would raise an exception
78
- Other: pinned to `pandas<=2.1` and `urllib3>=1.26` to avoid runtime errors in dbt-databricks (#330)
89

src/databricks/sqlalchemy/_parse.py

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def get_comment_from_dte_output(dte_output: List[Dict[str, str]]) -> Optional[st
305305
GET_COLUMNS_TYPE_MAP = {
306306
"boolean": sqlalchemy.types.Boolean,
307307
"smallint": sqlalchemy.types.SmallInteger,
308+
"tinyint": type_overrides.TINYINT,
308309
"int": sqlalchemy.types.Integer,
309310
"bigint": sqlalchemy.types.BigInteger,
310311
"float": sqlalchemy.types.Float,

src/databricks/sqlalchemy/_types.py

+4
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,7 @@ class TINYINT(sqlalchemy.types.TypeDecorator):
316316

317317
impl = sqlalchemy.types.SmallInteger
318318
cache_ok = True
319+
320+
@compiles(TINYINT, "databricks")
321+
def compile_tinyint(type_, compiler, **kw):
322+
return "TINYINT"

src/databricks/sqlalchemy/test_local/test_types.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_numeric_renders_as_decimal_with_precision(self):
111111
)
112112

113113
def test_numeric_renders_as_decimal_with_precision_and_scale(self):
114-
return self._assert_compiled_value_explicit(
114+
self._assert_compiled_value_explicit(
115115
sqlalchemy.types.Numeric(10, 2), "DECIMAL(10, 2)"
116116
)
117117

@@ -146,15 +146,16 @@ def test_bare_uppercase_types_compile(self, type_, expected):
146146
if isinstance(type_, type(sqlalchemy.types.ARRAY)):
147147
# ARRAY cannot be initialised without passing an item definition so we test separately
148148
# I preserve it in the uppercase_type_map for clarity
149-
return True
150-
return self._assert_compiled_value(type_, expected)
149+
assert True
150+
else:
151+
self._assert_compiled_value(type_, expected)
151152

152153
def test_array_string_renders_as_array_of_string(self):
153154
"""SQLAlchemy's ARRAY type requires an item definition. And their docs indicate that they've only tested
154155
it with Postgres since that's the only first-class dialect with support for ARRAY.
155156
156157
https://docs.sqlalchemy.org/en/20/core/type_basics.html#sqlalchemy.types.ARRAY
157158
"""
158-
return self._assert_compiled_value_explicit(
159+
self._assert_compiled_value_explicit(
159160
sqlalchemy.types.ARRAY(sqlalchemy.types.String), "ARRAY<STRING>"
160161
)

0 commit comments

Comments
 (0)