Skip to content

Added support for tinyint to _parse.py #315

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

Merged
merged 5 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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

## 3.0.1 (2023-12-01)
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(
Copy link
Contributor

Choose a reason for hiding this comment

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

I found during testing that this test case would always pass because prefixing an assertion with return always evaluates as a pass. When I removed the return, the test failed for TINYINT types (should have been caught during initial development). This test now passes.

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>"
)