Skip to content
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

chore(trino): remove unnecessary index checks #25211

Merged
merged 2 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions superset/db_engine_specs/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,13 @@ 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,
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

Expand All @@ -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}. "
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion superset/db_engine_specs/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading