:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-warehouse): exclude alias columns from clickhouse discovery (#74579)
Tom Owers5bd2d7ba772b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/clickhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/clickhouse.pyindex 540478f6a462..829a139eb909 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/clickhouse.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/clickhouse.py@@ -363,11 +363,18 @@ def get_schemas(params["names"] = tuple(names)names_filter = "AND table IN %(names)s"+ # Skip ALIAS and EPHEMERAL columns. A native `SELECT *` never touches them, but our+ # `SELECT *` expands to an explicit column list — so an ALIAS whose defining expression no+ # longer resolves on the server (a dropped/renamed underlying column, or one the connecting+ # user can't read) fails the whole query with UNKNOWN_IDENTIFIER (code 47), and EPHEMERAL+ # columns aren't selectable at all. Ordinary, DEFAULT and MATERIALIZED columns hold real,+ # selectable data and are kept.result = client.query(f"""SELECT table, name, typeFROM system.columnsWHERE database = %(database)s {names_filter}+ AND default_kind NOT IN ('ALIAS', 'EPHEMERAL')ORDER BY table ASC, position ASC""",parameters=params,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.pyindex cc8823249b33..49c7246098dd 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickhouse/test_clickhouse.py@@ -952,6 +952,27 @@ class TestGetSchemas:assert events_cols["id"] == ("UInt64", False)assert events_cols["name"] == ("Nullable(String)", True)+ def test_discovery_query_excludes_alias_and_ephemeral_columns(self):+ # A native `SELECT *` skips ALIAS/EPHEMERAL columns, but our `SELECT *` expands to an+ # explicit column list — an included ALIAS whose expression can't resolve breaks the whole+ # query with UNKNOWN_IDENTIFIER (code 47). The filter must stay in the discovery query.+ from products.warehouse_sources.backend.temporal.data_imports.sources.clickhouse import clickhouse as ch_module++ mock_client = self._make_mock_client([("events", "id", "UInt64")])+ with patch.object(ch_module, "_get_client", return_value=mock_client):+ ch_module.get_schemas(+ host="localhost",+ port=8443,+ database="default",+ user="default",+ password="",+ secure=True,+ verify=True,+ )++ queries = [str(call.args[0]) for call in mock_client.query.call_args_list]+ assert any("default_kind NOT IN ('ALIAS', 'EPHEMERAL')" in q for q in queries)+def test_excludes_materialized_view_inner_tables(self):from products.warehouse_sources.backend.temporal.data_imports.sources.clickhouse import clickhouse as ch_module