fix: add suffix to Drill labels to avoid collision (#32857)

Co-authored-by: Fredrik Hyyrynen <fredrik.hyyrynen@ngm.se>
Co-authored-by: Evan Rusackas <evan@rusackas.com>
Co-authored-by: pre-commit <pre-commit@users.noreply.github.com>
This commit is contained in:
Fredrik Hyyrynen
2025-06-26 20:28:05 +02:00
committed by GitHub
parent a56d7252c2
commit eec563b0b4
2 changed files with 28 additions and 0 deletions

View File

@@ -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]}"

View File

@@ -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