aminghadersohi commented on code in PR #42793:
URL: https://github.com/apache/superset/pull/42793#discussion_r3732320608
##########
UPDATING.md:
##########
@@ -24,6 +24,19 @@ assists people when migrating to a new version.
## Next
+### ClickHouse: column aliases regain a short hash suffix
+
+Column aliases in generated ClickHouse queries (e.g. `create_time_b16a62`
Review Comment:
Under the default `HASH_ALGORITHM = "sha256"` (`config.py:259`),
`hash_from_str("create_time")[:6]` is `b09621`, so the generated alias is
`create_time_b09621`. `b16a62` is the **md5** digest — only correct when an
operator overrides `HASH_ALGORITHM="md5"`. Consider using the sha256 value (or
noting the config dependency) so the example matches a default deployment.
##########
tests/unit_tests/db_engine_specs/test_clickhouse.py:
##########
@@ -616,3 +616,45 @@ def test_use_equality_for_boolean_filters_property() ->
None:
from superset.db_engine_specs.clickhouse import ClickHouseBaseEngineSpec
assert ClickHouseBaseEngineSpec.use_equality_for_boolean_filters is True
+
+
+def test_clickhouse_mutate_label_suffixes_hash() -> None:
+ """Regression test for #40289.
+
+ ``_mutate_label`` must append a 6-char hash suffix so that column
+ aliases in ``SELECT expr AS alias`` never collide lexically with
+ subquery column names of the same name. Without this suffix,
+ ClickHouse 25.3+ raises ``Code: 215`` on charts against virtual
+ datasets, even though the SELECT and GROUP BY expressions are
+ lexically identical.
+ """
+ from superset.db_engine_specs.clickhouse import ClickHouseBaseEngineSpec
+ from superset.utils.hashing import hash_from_str
+
+ for label in ("create_time", "revenue", "sum(A)/sum(B)"):
+ expected = f"{label}_{hash_from_str(label)[:6]}"
+ assert ClickHouseBaseEngineSpec._mutate_label(label) == expected
Review Comment:
Endorsing codeant's note here: `expected` is built with the same
`f"{label}_{hash_from_str(label)[:6]}"` formula as the production method, so
this assertion can't catch a changed hash algorithm, input, or suffix length —
only a fully dropped suffix. Confirmed by reverting the production
`_mutate_label`: this is the *only* one of the three new tests that fails; the
determinism and uniqueness tests pass even against an identity `_mutate_label`.
Consider asserting a fixed literal (e.g. `create_time_b09621` under the default
sha256) or an implementation-independent invariant instead.
--
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]