From 255fcaceda7caaf009ad4bae08b079c035260fb4 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Wed, 6 Sep 2023 11:04:56 -0700 Subject: [PATCH 1/2] chore(trino): remove unnecessary index checks --- superset/db_engine_specs/presto.py | 8 ++++++-- superset/db_engine_specs/trino.py | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/superset/db_engine_specs/presto.py b/superset/db_engine_specs/presto.py index c05865b871a73..fab8aa9ca23c1 100644 --- a/superset/db_engine_specs/presto.py +++ b/superset/db_engine_specs/presto.py @@ -533,6 +533,7 @@ def latest_partition( schema: str | None, database: Database, show_first: bool = False, + indexes: list[dict[str, Any]] | None = None, ) -> tuple[list[str], list[str] | None]: """Returns col name and the latest (max) partition value for a table @@ -542,12 +543,15 @@ def latest_partition( :type database: models.Database :param show_first: displays the value for the first partitioning key if there are many partitioning keys + :param indexes: indexes from the database :type show_first: bool >>> latest_partition('foo_table') (['ds'], ('2018-01-01',)) """ - indexes = database.get_indexes(table_name, schema) + if indexes is None: + indexes = database.get_indexes(table_name, schema) + if not indexes: raise SupersetTemplateException( f"Error getting partition for {schema}.{table_name}. " @@ -1221,7 +1225,7 @@ def extra_table_metadata( if indexes := database.get_indexes(table_name, schema_name): col_names, latest_parts = cls.latest_partition( - table_name, schema_name, database, show_first=True + table_name, schema_name, database, show_first=True, indexes=indexes ) if not latest_parts: diff --git a/superset/db_engine_specs/trino.py b/superset/db_engine_specs/trino.py index da0a56e10033a..fb03a725bc418 100644 --- a/superset/db_engine_specs/trino.py +++ b/superset/db_engine_specs/trino.py @@ -58,7 +58,11 @@ def extra_table_metadata( if indexes := database.get_indexes(table_name, schema_name): col_names, latest_parts = cls.latest_partition( - table_name, schema_name, database, show_first=True + table_name, + schema_name, + database, + show_first=True, + indexes=indexes, ) if not latest_parts: From ece021569129b08d98fbe2192153616eeedb7da8 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Wed, 6 Sep 2023 13:21:17 -0700 Subject: [PATCH 2/2] lint --- superset/db_engine_specs/presto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset/db_engine_specs/presto.py b/superset/db_engine_specs/presto.py index fab8aa9ca23c1..dfb82877a678d 100644 --- a/superset/db_engine_specs/presto.py +++ b/superset/db_engine_specs/presto.py @@ -527,7 +527,7 @@ def _latest_partition_from_df(cls, df: pd.DataFrame) -> list[str] | None: @classmethod @cache_manager.data_cache.memoize(timeout=60) - def latest_partition( + def latest_partition( # pylint: disable=too-many-arguments cls, table_name: str, schema: str | None,