Skip to content

Add support for table comments - #308

Merged
susodapop merged 12 commits into
databricks:sqlalchemy-stagingfrom
cbornet:table-comment
Jan 23, 2024
Merged

Add support for table comments#308
susodapop merged 12 commits into
databricks:sqlalchemy-stagingfrom
cbornet:table-comment

Conversation

@cbornet

@cbornet cbornet commented Dec 27, 2023

Copy link
Copy Markdown

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

@cbornet cbornet Jan 2, 2024

Copy link
Copy Markdown
Author

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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Nice 👍

Comment thread src/databricks/sqlalchemy/_information_schema.py Outdated
@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
Copy Markdown

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

@NadirJ

NadirJ commented Jan 23, 2024

Copy link
Copy Markdown

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

NadirJ commented Jan 23, 2024

Copy link
Copy Markdown

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

@susodapop

susodapop commented Jan 23, 2024 via email

Copy link
Copy Markdown
Contributor

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

susodapop commented Jan 23, 2024

Copy link
Copy Markdown
Contributor

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>

@susodapop susodapop left a comment

Copy link
Copy Markdown
Contributor

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.

"""
if column is column.table._autoincrement_column or column.autoincrement is True:
logger.warn(
logger.warning(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch 🙏

Comment thread src/databricks/sqlalchemy/pytest.ini Outdated

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

Copy link
Copy Markdown
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?

pass


class FutureTableDDLTest(FutureTableDDLTest):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perfect!

TIMEZONE_OPT = "timezone-optional TIMESTAMP fields"
TRANSACTIONS = "transactions"
UNIQUE = "UNIQUE constraints"
DROP_TBL = "drop table comment"

Copy link
Copy Markdown
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>
Comment thread src/databricks/sqlalchemy/base.py Outdated
table_name=table_name,
schema_name=schema,
)
# Type ignore is because mypy knows that self._describe_table_extended *can*

Copy link
Copy Markdown
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
Copy Markdown
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
@susodapop

Copy link
Copy Markdown
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

cbornet commented Jan 24, 2024

Copy link
Copy Markdown
Author

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