Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
chore: Refactor [Presto|Trino]EngineSpec._partition_query (apache#23944)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4ef9d25)
  • Loading branch information
john-bodley committed May 22, 2023
1 parent 9c28f32 commit 02d3d53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
3 changes: 2 additions & 1 deletion superset/db_engine_specs/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ def _partition_query( # pylint: disable=too-many-arguments
order_by: Optional[List[Tuple[str, bool]]] = None,
filters: Optional[Dict[Any, Any]] = None,
) -> str:
return f"SHOW PARTITIONS {table_name}"
full_table_name = f"{schema}.{table_name}" if schema else table_name
return f"SHOW PARTITIONS {full_table_name}"

@classmethod
def select_star( # pylint: disable=too-many-arguments
Expand Down
24 changes: 12 additions & 12 deletions superset/db_engine_specs/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,19 @@ def _partition_query( # pylint: disable=too-many-arguments,too-many-locals,unus
l.append(f"{field} = '{value}'")
where_clause = "WHERE " + " AND ".join(l)

presto_version = database.get_extra().get("version")

# Partition select syntax changed in v0.199, so check here.
# Default to the new syntax if version is unset.
partition_select_clause = (
f'SELECT * FROM "{table_name}$partitions"'
if not presto_version or Version(presto_version) >= Version("0.199")
else f"SHOW PARTITIONS FROM {table_name}"
)
presto_version = database.get_extra().get("version")

if presto_version and Version(presto_version) < Version("0.199"):
full_table_name = f"{schema}.{table_name}" if schema else table_name
partition_select_clause = f"SHOW PARTITIONS FROM {full_table_name}"
else:
system_table_name = f'"{table_name}$partitions"'
full_table_name = (
f"{schema}.{system_table_name}" if schema else system_table_name
)
partition_select_clause = f"SELECT * FROM {full_table_name}"

sql = dedent(
f"""\
Expand Down Expand Up @@ -1222,11 +1226,7 @@ def extra_table_metadata(
"cols": sorted(indexes[0].get("column_names", [])),
"latest": dict(zip(col_names, latest_parts)),
"partitionQuery": cls._partition_query(
table_name=(
f"{schema_name}.{table_name}"
if schema_name and "." not in table_name
else table_name
),
table_name=table_name,
schema=schema_name,
indexes=indexes,
database=database,
Expand Down
6 changes: 1 addition & 5 deletions superset/db_engine_specs/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ def extra_table_metadata(
),
"latest": dict(zip(col_names, latest_parts)),
"partitionQuery": cls._partition_query(
table_name=(
f"{schema_name}.{table_name}"
if schema_name and "." not in table_name
else table_name
),
table_name=table_name,
schema=schema_name,
indexes=indexes,
database=database,
Expand Down

0 comments on commit 02d3d53

Please sign in to comment.