You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "betodealmeida (via GitHub)" <gi...@apache.org> on 2024/04/18 13:32:50 UTC
[PR] feat(SIP-95): new endpoint for table metadata [superset]
betodealmeida opened a new pull request, #28122:
URL: https://github.com/apache/superset/pull/28122
<!---
Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
Example:
fix(dashboard): load charts correctly
-->
### SUMMARY
<!--- Describe the change below, including rationale and design decisions -->
This PR is stacked on https://github.com/apache/superset/pull/28063. It adds a new endpoint to get metadata from a table, optionally passing a schema and a catalog.
Currently the catalog is a no-op, but in the next PR I'll start implementing support for enabling catalogs in databases and specifying them when building queries or datasets.
In addition to the new endpoint, this PR refactors the logic passes `table_name` and `schema` around. Most methods were updated to take a `Table` instance instead, which is a dataclass holding a table name, an optional schema, and an optional catalog:
https://github.com/apache/superset/blob/69a7bfc88d7aac3cb08cb45376be1699a67ebee0/superset/sql_parse.py#L242-L250
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
<!--- Skip this if not applicable -->
N/A
### TESTING INSTRUCTIONS
<!--- Required! What steps can be taken to manually verify the changes? -->
I added unit tests for the new endpoint, and updated existing tests.
### ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
- [X] Has associated issue: https://github.com/apache/superset/issues/22862
- [ ] Required feature flags:
- [ ] Changes UI
- [X] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [X] Migration is atomic, supports rollback & is backwards-compatible
- [X] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [X] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1576718422
##########
superset/databases/utils.py:
##########
@@ -51,30 +62,27 @@ def get_col_type(col: dict[Any, Any]) -> str:
return dtype
-def get_table_metadata(
- database: Any, table_name: str, schema_name: Optional[str]
-) -> dict[str, Any]:
+def get_table_metadata(database: Any, table: Table) -> TableMetadataResponse:
Review Comment:
should the database type be a Database model?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1570968411
##########
superset/models/dashboard.py:
##########
@@ -214,13 +214,6 @@ def datasources(self) -> set[BaseDatasource]:
def charts(self) -> list[str]:
return [slc.chart for slc in self.slices]
- @property
- def sqla_metadata(self) -> None:
- # pylint: disable=no-member
- with self.get_sqla_engine() as engine:
- meta = MetaData(bind=engine)
- meta.reflect()
-
Review Comment:
This is not used anywhere, AFAICT.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1570784700
##########
superset/models/core.py:
##########
@@ -415,22 +425,21 @@ def get_sqla_engine(
server_context.local_bind_address,
)
sqlalchemy_uri = ssh_manager_factory.instance.build_sqla_url(
- sqlalchemy_uri, server_context
+ sqlalchemy_uri,
+ server_context,
)
+
yield self._get_sqla_engine(
+ catalog=catalog,
schema=schema,
nullpool=nullpool,
source=source,
sqlalchemy_uri=sqlalchemy_uri,
)
- # The `get_sqla_engine_with_context` was renamed to `get_sqla_engine`, but we kept a
- # reference to the old method to prevent breaking third-party applications.
- # TODO (betodealmeida): Remove in 5.0
- get_sqla_engine_with_context = get_sqla_engine
Review Comment:
I removed this because the signature for `get_sqla_engine` changed to accept a catalog.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida merged PR #28122:
URL: https://github.com/apache/superset/pull/28122
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1576892178
##########
superset/databases/utils.py:
##########
@@ -51,30 +62,27 @@ def get_col_type(col: dict[Any, Any]) -> str:
return dtype
-def get_table_metadata(
- database: Any, table_name: str, schema_name: Optional[str]
-) -> dict[str, Any]:
+def get_table_metadata(database: Any, table: Table) -> TableMetadataResponse:
Review Comment:
Yeah, good catch!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1576712213
##########
superset/databases/api.py:
##########
@@ -843,7 +844,86 @@ def table_extra_metadata_deprecated(
payload = database.db_engine_spec.get_extra_table_metadata(database, table)
return self.response(200, **payload)
- @expose("/<int:pk>/table_metadata/extra/", methods=("GET",))
Review Comment:
This looks like a breaking change?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1575303604
##########
superset/models/dashboard.py:
##########
@@ -214,13 +214,6 @@ def datasources(self) -> set[BaseDatasource]:
def charts(self) -> list[str]:
return [slc.chart for slc in self.slices]
- @property
- def sqla_metadata(self) -> None:
- # pylint: disable=no-member
- with self.get_sqla_engine() as engine:
- meta = MetaData(bind=engine)
- meta.reflect()
-
Review Comment:
```bash
/Users/beto/Projects/superset/superset (new-table-metadata-api)$ git grep '\.sqla_metadata'
/Users/beto/Projects/superset/superset (new-table-metadata-api)$
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1570782736
##########
superset/models/core.py:
##########
@@ -403,7 +413,7 @@ def get_sqla_engine(
# if ssh_tunnel is available build engine with information
engine_context = ssh_manager_factory.instance.create_tunnel(
ssh_tunnel=ssh_tunnel,
- sqlalchemy_database_uri=self.sqlalchemy_uri_decrypted,
Review Comment:
See line 396 above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1570785432
##########
superset/models/core.py:
##########
@@ -447,26 +456,10 @@ def _get_sqla_engine(
params["poolclass"] = NullPool
connect_args = params.get("connect_args", {})
- # The ``adjust_database_uri`` method was renamed to ``adjust_engine_params`` and
- # had its signature changed in order to support more DB engine specs. Since DB
- # engine specs can be released as 3rd party modules we want to make sure the old
- # method is still supported so we don't introduce a breaking change.
- if hasattr(self.db_engine_spec, "adjust_database_uri"):
- sqlalchemy_url = self.db_engine_spec.adjust_database_uri(
- sqlalchemy_url,
- schema,
- )
- logger.warning(
- "DB engine spec %s implements the method `adjust_database_uri`, which is "
- "deprecated and will be removed in version 3.0. Please update it to "
- "implement `adjust_engine_params` instead.",
- self.db_engine_spec,
- )
Review Comment:
We're on 4.0 now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1575304453
##########
superset/models/dashboard.py:
##########
@@ -214,13 +214,6 @@ def datasources(self) -> set[BaseDatasource]:
def charts(self) -> list[str]:
return [slc.chart for slc in self.slices]
- @property
- def sqla_metadata(self) -> None:
- # pylint: disable=no-member
- with self.get_sqla_engine() as engine:
- meta = MetaData(bind=engine)
- meta.reflect()
-
Review Comment:
In fact, after I removed this property there are no occurrences of `sqla_metadata` in the codebase:
```bash
/Users/beto/Projects/superset (new-table-metadata-api)$ git grep sqla_metadata
/Users/beto/Projects/superset (new-table-metadata-api)$
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(SIP-95): new endpoint for table metadata [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on code in PR #28122:
URL: https://github.com/apache/superset/pull/28122#discussion_r1576712213
##########
superset/databases/api.py:
##########
@@ -843,7 +844,86 @@ def table_extra_metadata_deprecated(
payload = database.db_engine_spec.get_extra_table_metadata(database, table)
return self.response(200, **payload)
- @expose("/<int:pk>/table_metadata/extra/", methods=("GET",))
Review Comment:
This looks like a breaking change?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org