joe-clickhouse commented on code in PR #34091:
URL: https://github.com/apache/superset/pull/34091#discussion_r2818764647


##########
superset/db_engine_specs/clickhouse.py:
##########
@@ -519,15 +519,41 @@ def validate_parameters(
         return []
 
     @staticmethod
-    def _mutate_label(label: str) -> str:
+    def _mutate_label(label: str, database: Database | None = None) -> str:
         """
-        Suffix with the first six characters from the md5 of the label to avoid
-        collisions with original column names
+        Conditionally suffix the label with the first six characters from the 
md5
+        of the label to avoid collisions with original column names.
+
+        By default, labels are mutated for backward compatibility. To disable 
this
+        behavior on a per-database basis, set `mutate_label_name` to `false` in
+        the database's "extra" JSON configuration in the Superset UI:
+
+            {
+                "mutate_label_name": false
+            }
+
+        This is useful when your ClickHouse queries refer to their own aliases
+        within the same SELECT statement.
 
         :param label: Expected expression label
-        :return: Conditionally mutated label
+        :param database: Database instance for db-specific label mutation logic
+        :return: Mutated label if mutation is enabled, otherwise the original 
label
         """
-        return f"{label}_{hash_from_str(label)[:6]}"
+        mutate_label = True
+
+        if database:
+            try:
+                extra = database.get_extra()
+                mutate_label = extra.get("mutate_label_name", True)
+            except Exception:  # pylint: disable=broad-except
+                logger.warning(
+                    "Error retrieving mutate_label_name setting. Falling back 
to "
+                    "default behavior of True."

Review Comment:
   I think the broad exception here is ok. `get_extra()` calls 
`get_extra_params()` which could raise `json.JSONDecodeError` and isn't even 
the suggested list. Other error types could be potentially raised along the way 
as well. This is a simple label formatting helper limited to the clickhouse 
spec so if anything goes wrong, no matter what it is, it'd be preferable to 
fall back to default rather than crash.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to