Skip to content

Commit

Permalink
BW-2722: add param to indicate metadata fetch query
Browse files Browse the repository at this point in the history
  • Loading branch information
oOhyeahh authored and t-abhay09 committed Aug 8, 2024
1 parent eb089ed commit f166544
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion superset/db_engine_specs/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def get_catalog_names(
In BigQuery, a catalog is called a "project".
"""
engine: Engine
with database.get_sqla_engine_with_context() as engine:
with database.get_sqla_engine_with_context(fetch_metadata=True) as engine:
client = cls._get_client(engine)
projects = client.list_projects()

Expand Down
15 changes: 10 additions & 5 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def get_sqla_engine_with_context(
nullpool: bool = True,
source: utils.QuerySource | None = None,
override_ssh_tunnel: SSHTunnel | None = None,
fetch_metadata: bool = False
) -> Engine:
from superset.daos.database import ( # pylint: disable=import-outside-toplevel
DatabaseDAO,
Expand Down Expand Up @@ -417,6 +418,7 @@ def get_sqla_engine_with_context(
nullpool=nullpool,
source=source,
sqlalchemy_uri=sqlalchemy_uri,
fetch_metadata=fetch_metadata
)

def _get_sqla_engine(
Expand All @@ -425,6 +427,7 @@ def _get_sqla_engine(
nullpool: bool = True,
source: utils.QuerySource | None = None,
sqlalchemy_uri: str | None = None,
fetch_metadata: bool = False
) -> Engine:
sqlalchemy_url = make_url_safe(
sqlalchemy_uri if sqlalchemy_uri else self.sqlalchemy_uri_decrypted
Expand Down Expand Up @@ -500,6 +503,7 @@ def _get_sqla_engine(
effective_username,
security_manager,
source,
fetch_metadata
)
try:
return create_engine(sqlalchemy_url, **params)
Expand Down Expand Up @@ -736,7 +740,8 @@ def get_inspector_with_context(
self, ssh_tunnel: SSHTunnel | None = None
) -> Inspector:
with self.get_sqla_engine_with_context(
override_ssh_tunnel=ssh_tunnel
override_ssh_tunnel=ssh_tunnel,
fetch_metadata = True
) as engine:
yield sqla.inspect(engine)

Expand Down Expand Up @@ -817,7 +822,7 @@ def update_params_from_encrypted_extra(self, params: dict[str, Any]) -> None:
def get_table(self, table_name: str, schema: str | None = None) -> Table:
extra = self.get_extra()
meta = MetaData(**extra.get("metadata_params", {}))
with self.get_sqla_engine_with_context() as engine:
with self.get_sqla_engine_with_context(fetch_metadata=True) as engine:
return Table(
table_name,
meta,
Expand Down Expand Up @@ -921,11 +926,11 @@ def get_perm(self) -> str:
return self.perm # type: ignore

def has_table(self, table: Table) -> bool:
with self.get_sqla_engine_with_context() as engine:
with self.get_sqla_engine_with_context(fetch_metadata=True) as engine:
return engine.has_table(table.table_name, table.schema or None)

def has_table_by_name(self, table_name: str, schema: str | None = None) -> bool:
with self.get_sqla_engine_with_context() as engine:
with self.get_sqla_engine_with_context(fetch_metadata=True) as engine:
return engine.has_table(table_name, schema)

@classmethod
Expand All @@ -944,7 +949,7 @@ def _has_view(
return view_name in view_names

def has_view(self, view_name: str, schema: str | None = None) -> bool:
with self.get_sqla_engine_with_context(schema) as engine:
with self.get_sqla_engine_with_context(schema, fetch_metadata=True) as engine:
return engine.run_callable(
self._has_view, engine.dialect, view_name, schema
)
Expand Down

0 comments on commit f166544

Please sign in to comment.