Skip to content
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

Added support for tinyint to _parse.py #315

Merged
merged 5 commits into from
Jan 25, 2024

Conversation

TimTheinAtTabs
Copy link
Contributor

Using SqlAlchemy to reflect on a table having a tinyint column throws an error because tinyint type was missing from the type map. Adding a single line to the code seems to have fixed the bug.

Copy link
Contributor

@susodapop susodapop left a comment

Choose a reason for hiding this comment

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

Thank you! We'll need to add a couple tests for this behaviour before merging.

@susodapop
Copy link
Contributor

Please push an update to your commit including the DCO sign-off as described here.

Copy link
Contributor

@susodapop susodapop left a comment

Choose a reason for hiding this comment

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

Sorry for the chatter. I clicked the approve button prematurely. One comment for you:

Before we can merge:

  1. We need to add e2e / unit tests for this. I can do this for you if you're not able to do so easily.
  2. We can't merge this change without a DCO sign-off on your commit. Please amend your commit and push it to your branch.

@@ -282,6 +282,7 @@ def get_pk_strings_from_dte_output(
GET_COLUMNS_TYPE_MAP = {
"boolean": sqlalchemy.types.Boolean,
"smallint": sqlalchemy.types.SmallInteger,
"tinyint": sqlalchemy.types.SmallInteger,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be type_overrides.TINYINT, not SmallInteger, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not know enough of the code to make the judgement call. I used my best guess to figure out the quickest solution that could work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Understood. Databricks has both SMALLINT and TINYINT types. The code you're editing has to do with column reflection of existing tables. These are mapped to SqlAlchemy types named SmallInteger (which is built-in to SQLAlchemy) and TINYINT (which is a custom type implemented in our dialect). In Python, a TINYINT in our dialect behaves exactly the same as a SmallInteger (Python doesn't have any size restrictions for integers). That's why your version of the code works for your use case. But we should reflect the type properly back as `type_overrides.TINYINT. Otherwise SQLAlchemy will not properly reflect back the true schema of the table, which will be an issue for people using SQLAlchemy/Alembic to programmatically manage their table schemas.

and fix pytest warning around returning an assertion

Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
@susodapop
Copy link
Contributor

I've pushed a fix that properly tests this behaviour. Can you update your commit with the DCO sign-off?

Jesse Whitehouse added 2 commits January 25, 2024 16:00
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
@@ -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.

Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
@susodapop susodapop merged commit c71e081 into databricks:main Jan 25, 2024
7 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants