mistercrunch commented on code in PR #34766:
URL: https://github.com/apache/superset/pull/34766#discussion_r2289298574
##########
superset/db_engine_specs/bigquery.py:
##########
@@ -828,3 +828,97 @@ def parse_error_exception(cls, exception: Exception) ->
Exception:
# If for some reason we get an exception, for example, no new line
# We will return the original exception
return exception
+
+ @classmethod
+ def get_materialized_view_names(
+ cls,
+ database: Database,
+ inspector: Inspector,
+ schema: str | None,
+ ) -> set[str]:
+ """
+ Get all materialized views from BigQuery.
+
+ BigQuery materialized views are not returned by the standard
+ get_view_names() method, so we need to query INFORMATION_SCHEMA
directly.
+ """
+ if not schema:
+ return set()
+
+ # Construct the query to get materialized views from INFORMATION_SCHEMA
+ if catalog := database.get_default_catalog():
+ information_schema =
f"`{catalog}.{schema}.INFORMATION_SCHEMA.TABLES`"
+ else:
+ information_schema = f"`{schema}.INFORMATION_SCHEMA.TABLES`"
+
+ # Use string formatting for the table name since it's not user input
+ # The catalog and schema are from trusted sources (database
configuration)
+ query = f"""
+ SELECT table_name
+ FROM {information_schema}
+ WHERE table_type = 'MATERIALIZED VIEW'
+ """ # noqa: S608
+
+ materialized_views = set()
+ try:
+ with database.get_raw_connection(catalog=catalog, schema=schema)
as conn:
Review Comment:
would love to reduce the number of places where we handle raw
connections/cursors, wondering if there's already something we can use
somewhere handy. Seem DbEngineSpec must have a `query` or `get_results` or
something!
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]