diff --git a/superset/db_engine_specs/drill.py b/superset/db_engine_specs/drill.py index 167ed386ea2..5a49f5993ae 100644 --- a/superset/db_engine_specs/drill.py +++ b/superset/db_engine_specs/drill.py @@ -27,6 +27,7 @@ from sqlalchemy.engine.url import URL from superset.constants import TimeGrain from superset.db_engine_specs.base import BaseEngineSpec from superset.db_engine_specs.exceptions import SupersetDBAPIProgrammingError +from superset.utils.hashing import md5_sha_from_str if TYPE_CHECKING: from superset.models.core import Database @@ -143,3 +144,14 @@ class DrillEngineSpec(BaseEngineSpec): if str(ex) == "generator raised StopIteration": return [] raise + + @staticmethod + def _mutate_label(label: str) -> str: + """ + Suffix with the first six characters from the md5 of the label to avoid + collisions with original column names + + :param label: Expected expression label + :return: Conditionally mutated label + """ + return f"{label}_{md5_sha_from_str(label)[:6]}" diff --git a/tests/unit_tests/db_engine_specs/test_drill.py b/tests/unit_tests/db_engine_specs/test_drill.py index 366190eaaa7..60a455e8afc 100644 --- a/tests/unit_tests/db_engine_specs/test_drill.py +++ b/tests/unit_tests/db_engine_specs/test_drill.py @@ -157,3 +157,19 @@ def test_get_schema_from_engine_params() -> None: ) == "dfs.test" ) + + +@pytest.mark.parametrize( + "column_name,expected_result", + [ + ("time", "time_07cc69"), + ("count", "count_e2942a"), + ], +) +def test_connect_make_label_compatible(column_name: str, expected_result: str) -> None: + from superset.db_engine_specs.drill import ( + DrillEngineSpec as spec, # noqa: N813 + ) + + label = spec.make_label_compatible(column_name) + assert label == expected_result