Skip to content

feat(api): append cooments of column and table for metadata api #812

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 15 commits into from
Oct 4, 2024

Conversation

grieve54706
Copy link
Contributor

This pull request includes several changes aimed at improving the metadata handling for various database connections in the ibis-server project. The most important changes include removing unnecessary json imports, updating methods to use to_dict instead of to_json, adding connection initialization in constructors, and enhancing the SQL queries to fetch additional metadata.

Codebase Simplification:

  • Removed unnecessary json imports across multiple files

Method Updates:

  • Updated methods to use to_dict instead of to_json for converting SQL query results to dictionaries.

Connection Initialization:

  • Added connection initialization in the constructors for ClickHouseMetadata, MSSQLMetadata, MySQLMetadata, and PostgresMetadata classes.

SQL Query Enhancements:

  • Enhanced SQL queries to include additional metadata such as table and column comments.

Factory Pattern:

  • Refactored MetadataFactory to use a mapping dictionary for cleaner and more maintainable code.

These changes collectively enhance the maintainability, readability, and functionality of the metadata handling code in the ibis-server project.

Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

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

Thanks @grieve54706 working on this.
It seems that this PR doesn't implement for BigQuery to get the comment of tables or columns. Is there any plan for it?

DataSource.mssql: MSSQLMetadata,
DataSource.mysql: MySQLMetadata,
DataSource.postgres: PostgresMetadata,
DataSource.snowflake: SnowflakeMetadata,
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems Snowflake metadata is no yet supported. Maybe we can remove it from the mapping and throw NoImplementedError if someone uses it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

Comment on lines 23 to 38
SELECT
t.table_catalog,
t.table_schema,
t.table_name,
c.column_name,
c.data_type,
c.is_nullable,
c.column_comment
FROM
information_schema.tables AS t
INNER JOIN
information_schema.columns AS c
ON t.table_catalog = c.table_catalog
AND t.table_schema = c.table_schema
AND t.table_name = c.table_name
WHERE t.table_schema = '{schema}'
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't try it but maybe we can merge it with the table comments query? Something like

SELECT
    t.table_catalog,
    t.table_schema,
    t.table_name,
    c.column_name,
    c.data_type,
    c.is_nullable,
    c.column_comment,
    tc.comment
FROM
    information_schema.tables AS t
INNER JOIN
    information_schema.columns AS c
    ON t.table_catalog = c.table_catalog
    AND t.table_schema = c.table_schema
    AND t.table_name = c.table_name
INNER JOIN
    system.metadata.table_comments AS tc
    ON t.table_schema = tc.schema_name
    AND t.table_name = tc.table_name
WHERE t.table_schema = '{schema}'

Copy link
Contributor Author

@grieve54706 grieve54706 Oct 3, 2024

Choose a reason for hiding this comment

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

No. Trino does not implement getTableHandle for SystemTablesMetadata. It will fail when executing.
After implementing it again, it worked. Thank you for the nice idea.

Comment on lines +86 to +102
text("""
EXEC sys.sp_addextendedproperty
@name = N'MS_Description',
@value = N'This is a table comment',
@level0type = N'SCHEMA', @level0name = 'dbo',
@level1type = N'TABLE', @level1name = 'orders';
""")
)
conn.execute(
text("""
EXEC sys.sp_addextendedproperty
@name = N'MS_Description',
@value = N'This is a comment',
@level0type = N'SCHEMA', @level0name = 'dbo',
@level1type = N'TABLE', @level1name = 'orders',
@level2type = N'COLUMN', @level2name = 'o_comment';
""")
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@grieve54706
Copy link
Contributor Author

grieve54706 commented Oct 3, 2024

Thanks @grieve54706 working on this. It seems that this PR doesn't implement for BigQuery to get the comment of tables or columns. Is there any plan for it?

Already implemented this feature for BigQuery.

@@ -97,7 +115,7 @@ def test_query(trino: TrinoContainer):
"1996-01-02",
"1_370",
"2024-01-01 23:59:59.000000",
"2024-01-01 23:59:59.000000 UTC",
"2024-01-01 23:59:59.000000",
Copy link
Contributor

Choose a reason for hiding this comment

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

We didn't change the MDL and input data. Why does this value change? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We changed the expression before, but we did not run CI for trino and did not change the excepted (#782)

@goldmedal
Copy link
Contributor

There are some conflicts here. @grieve54706

@grieve54706 grieve54706 force-pushed the feature/metadata-api branch from 9364cdd to 53247f0 Compare October 4, 2024 05:47
Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

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

Thanks @grieve54706 overall LGTM.

@grieve54706 grieve54706 merged commit 861f978 into main Oct 4, 2024
6 checks passed
@grieve54706 grieve54706 deleted the feature/metadata-api branch October 4, 2024 06:20
grieve54706 added a commit that referenced this pull request Dec 13, 2024
* feat(clickhouse): append comments of column and table

* feat(clickhouse): append comments of column and table

* feat(mssql): append comments of column and table

* feat(mysql): append comments of column and table

* feat(postgres): append comments of column and table

* fix(trino): wait trino container ready to avoid 'nodes is empty' from Trino

* feat(trino): append comments of column and table

* chore(test): sort func and rename func

* test(snowflake): mark not implemented feature

* refactor(metadata): tidy up

* chore(metadata): remove unimplemented data source

* fix(trino): fix connection

* chore(trino): merge two statement

* test(trino): update excepted

we changed expression but did not update excepted on #782
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants