Skip to content

Commit

Permalink
SQLAlchemy: TINYINT types didn't reflect properly (#315)
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
  • Loading branch information
TimTheinAtTabs authored Jan 25, 2024
1 parent 4bb3c9e commit c71e081
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# 3.1.0 (TBD)

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

Expand Down
1 change: 1 addition & 0 deletions src/databricks/sqlalchemy/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def get_comment_from_dte_output(dte_output: List[Dict[str, str]]) -> Optional[st
GET_COLUMNS_TYPE_MAP = {
"boolean": sqlalchemy.types.Boolean,
"smallint": sqlalchemy.types.SmallInteger,
"tinyint": type_overrides.TINYINT,
"int": sqlalchemy.types.Integer,
"bigint": sqlalchemy.types.BigInteger,
"float": sqlalchemy.types.Float,
Expand Down
4 changes: 4 additions & 0 deletions src/databricks/sqlalchemy/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,7 @@ class TINYINT(sqlalchemy.types.TypeDecorator):

impl = sqlalchemy.types.SmallInteger
cache_ok = True

@compiles(TINYINT, "databricks")
def compile_tinyint(type_, compiler, **kw):
return "TINYINT"
9 changes: 5 additions & 4 deletions src/databricks/sqlalchemy/test_local/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_numeric_renders_as_decimal_with_precision(self):
)

def test_numeric_renders_as_decimal_with_precision_and_scale(self):
return self._assert_compiled_value_explicit(
self._assert_compiled_value_explicit(
sqlalchemy.types.Numeric(10, 2), "DECIMAL(10, 2)"
)

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

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

0 comments on commit c71e081

Please sign in to comment.