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

Add support for table comments #308

Merged
merged 12 commits into from
Jan 23, 2024

Conversation

cbornet
Copy link

@cbornet cbornet commented Dec 27, 2023

NB: I didn't find a way to get the comments of temporary views

  • temporary views don't appear in information_schema
  • DESCRIBE TABLE EXTENDED doesn't return anything for temporary views
  • SHOW CREATE TABLE isn't supported for temporary views
  • SHOW TABLE EXTENDED doesn't report comments for temporary views (it does for default views)
  • The thrift protocol TGetTablesResp message contains the temporary views but the REMARKS field is empty for all tables

The TCK tests test_comments_unicode and test_comments_unicode_full are still skipped at the moment since they also test column comments which are added in another PR: #306

Signed-off-by: Christophe Bornet <cbornet@hotmail.com>
Comment on lines 76 to 79
"""This test confirms that a table comment can be dropped.
The difference with TableDDLTest is that the comment value is '' and not None after
being dropped.
"""
Copy link
Author

@cbornet cbornet Jan 2, 2024

Choose a reason for hiding this comment

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

BTW this is surprising. From the docs we could expect the comment to be set to NULL and not ''.
But that's what I get when I test on databricks cloud.

Copy link
Contributor

Choose a reason for hiding this comment

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

I adapted for this in #328 by simply coercing the '' value into a NoneType. This passes SQLAlchemy's reusable tests.

Copy link
Author

Choose a reason for hiding this comment

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

Nice 👍

@cbornet cbornet force-pushed the table-comment branch 2 times, most recently from 5e82562 to e49eed3 Compare January 2, 2024 16:04
Signed-off-by: Christophe Bornet <cbornet@hotmail.com>
@nagyryan
Copy link

@susodapop can we get help taking a peek at this one?

@NadirJ
Copy link

NadirJ commented Jan 23, 2024

Hello @nagyryan @susodapop @yansonggao-db @andrefurlan-db can one you help @cbornet get this reviewed and merged please? For context @cbornet and I are working on some LangChain apps and require this PR. Ideally we would use an official release instead of using a fork. We know of other devs that in same situation too

@NadirJ
Copy link

NadirJ commented Jan 23, 2024

Please let @cbornet or I know if there is anything we can do to move this along

@susodapop
Copy link
Contributor

susodapop commented Jan 23, 2024 via email

@susodapop susodapop changed the base branch from main to sqlalchemy-staging January 23, 2024 20:36
@susodapop
Copy link
Contributor

susodapop commented Jan 23, 2024

I've updated the base branch to sqlalchemy-staging so we can incorporate the change in #306 here as well and update the changelog in one go.

[edit] also i merged in sqlalchemy-staging so we have the change from #306 and #328.

Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
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.

Overall the change code looks great. I'm running all the tests and going to add some unit tests for the statement rendering.

@@ -61,7 +67,7 @@ def get_column_specification(self, column, **kwargs):
feature in the future, similar to the Microsoft SQL Server dialect.
"""
if column is column.table._autoincrement_column or column.autoincrement is True:
logger.warn(
logger.warning(
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch 🙏

src/databricks/sqlalchemy/pytest.ini Outdated Show resolved Hide resolved

@requirements.comment_reflection
@util.provide_metadata
def test_drop_table_comment(self, connection):
Copy link
Contributor

Choose a reason for hiding this comment

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

Since I merged #328 do we still need to override this test?

@@ -251,36 +249,7 @@ class FutureWeCanSetDefaultSchemaWEventsTest(FutureWeCanSetDefaultSchemaWEventsT
pass


class FutureTableDDLTest(FutureTableDDLTest):
Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect!

@@ -55,6 +55,7 @@ class SkipReason(Enum):
TIMEZONE_OPT = "timezone-optional TIMESTAMP fields"
TRANSACTIONS = "transactions"
UNIQUE = "UNIQUE constraints"
DROP_TBL = "drop table comment"
Copy link
Contributor

Choose a reason for hiding this comment

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

Since '' is identical to None as far as sqlalchemy is concerned, I think we needn't list this as unsupported. We can just document the behaviour. Thoughts?

Jesse Whitehouse added 3 commits January 23, 2024 16:05
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
class. Scaffold in the Table Comment unit tests.

Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
table_name=table_name,
schema_name=schema,
)
# Type ignore is because mypy knows that self._describe_table_extended *can*
Copy link
Contributor

Choose a reason for hiding this comment

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

We can actually catch this using isinstance to avoid the mypy error like we do in get_pk_constraint.

Jesse Whitehouse added 4 commits January 23, 2024 17:04
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
@susodapop
Copy link
Contributor

I pushed a few commits making these changes:

  1. I removed the override for TableDDLTest since the OG test now passes.
  2. I added unit tests of the generated SQL for table comments
  3. I moved the logic for parsing table comments out of a DTE result into _parse.py so the logic is consistent.
  4. Added unit tests for item 2
  5. Added an e2e test for using Inspector to get a table comment. This is technically a duplicate of portions of TableDDLTest but I needed it anyway for debugging the new method in _parse.py so might as well keep it.

I concur with your choice not to use the thrift GetTables RPC for this. Eventually we will re-implement a lot of these methods using information_schema but for now, the output of DESCRIBE TABLE EXTENDED is the path forward.

This was missed in databricks#328

Signed-off-by: Jesse Whitehouse <jesse.whitehouse@databricks.com>
@susodapop susodapop merged commit f41a996 into databricks:sqlalchemy-staging Jan 23, 2024
1 check passed
@susodapop
Copy link
Contributor

@cbornet

Alrighty, I have merged this PR into the staging branch and then opened #329 to merge the staging branch into main. I would appreciate you giving that PR a look to make sure everything has been handled to your satisfaction.

@cbornet cbornet deleted the table-comment branch January 24, 2024 01:14
@cbornet
Copy link
Author

cbornet commented Jan 24, 2024

Awesome !
Thanks for your review and enhancements (cool solution for the '' comment!).

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.

4 participants