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

SQLAlchemy 2: implement and refactor schema reflection methods #249

Merged
merged 7 commits into from
Oct 13, 2023

Conversation

susodapop
Copy link
Contributor

Background

The biggest piece of work required for this PR was figuring how to get ComponentReflectionTest to even run as it's setUp and tearDown methods were failing for various reasons.

Description

This PR changes the has_table, get_pk_constraint, and get_foreign_keys methods into functional shape. They now pass the related tests in ComponentReflectionTest. get_foreign_keys is finished, following the guidance from @benc-db with regard to encapsulating strange parsing logic into more, smaller methods.

In a follow-up PR I will make the same refactor to get_pk_constraint, but I wanted to get eyes on the approach for get_foreign_keys before I proceed.

I implemented a new _describe_table_extended method that is re-used by severaral methods.

Jesse Whitehouse added 7 commits October 13, 2023 19:14
5 skipped, 3 warnings, 727 errors in 40.01s 

Signed-off-by: Jesse Whitehouse <[email protected]>
It requires the implementation of raising NoSuchTableError for the
different methods it checks.

And hooboy was this difficult to track down! I found that these tests were
mostly failing during setup and teardown because I didn't understand
that two different schemas are required.

This is covered in the SQLAlchemy tests documentation here:

https://github.com/sqlalchemy/sqlalchemy/blob/main/README.unittests.rst#database-configuration

The skipped tests happen because of exclusions, which is why the skip
log information isn't as pleasant as our other tests.

test_suite.py::ComponentReflectionTest_databricks+databricks::test_not_existing_table[get_check_constraints-_exclusions_06] SKIPPED
test_suite.py::ComponentReflectionTest_databricks+databricks::test_not_existing_table[get_columns-_exclusions_01] b'table_does_not_exists' PASSED
test_suite.py::ComponentReflectionTest_databricks+databricks::test_not_existing_table[get_foreign_keys-_exclusions_03] b'No such table table_does_not_exists' PASSED
test_suite.py::ComponentReflectionTest_databricks+databricks::test_not_existing_table[get_indexes-_exclusions_04] SKIPPED
test_suite.py::ComponentReflectionTest_databricks+databricks::test_not_existing_table[get_pk_constraint-_exclusions_02] b'No such table table_does_not_exists' PASSED
test_suite.py::ComponentReflectionTest_databricks+databricks::test_not_existing_table[get_table_comment-_exclusions_07] SKIPPED
test_suite.py::ComponentReflectionTest_databricks+databricks::test_not_existing_table[get_table_options-_exclusions_00] SKIPPED
test_suite.py::ComponentReflectionTest_databricks+databricks::test_not_existing_table[get_unique_constraints-_exclusions_05] SKIPPED

Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]>
This passes the HasTableTest test group in the dialect compliance
test suite

Signed-off-by: Jesse Whitehouse <[email protected]>
This now PASSES test_get_primary_keys and test_get_pk_constraint

Needs further refactor into actual parse methods...

Signed-off-by: Jesse Whitehouse <[email protected]>
Comment on lines +40 to +41
DBR_LTE_12_NOT_FOUND_STRING = "Table or view not found"
DBR_GT_12_NOT_FOUND_STRING = "TABLE_OR_VIEW_NOT_FOUND"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These duplicate lines will be removed in a subsequent PR.

@susodapop susodapop requested a review from benc-db October 13, 2023 23:28
DBR_LTE_12_NOT_FOUND_STRING = "Table or view not found"
DBR_GT_12_NOT_FOUND_STRING = "TABLE_OR_VIEW_NOT_FOUND"


Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is all of this stuff in init.py?

Copy link
Contributor Author

@susodapop susodapop Oct 13, 2023

Choose a reason for hiding this comment

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

It's a byproduct of earlier decisions. I'll move it out of init.py in a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The guidance from sqlalchemy is that this should be in a file called base.py.

Copy link
Collaborator

@benc-db benc-db left a comment

Choose a reason for hiding this comment

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

Approved assuming followup refactor from _init_,py to base.py. Documentation and style looks good.

@susodapop susodapop merged commit f0980ee into main Oct 13, 2023
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.

2 participants