Any chart with a series segment one_event_per_user and a property breakdown fails. Reproduced on current main (SQL below uses the DISTINCT ON form from #476).
Repro
Pie chart, series: event game_auth_verified, segment "One event per user", breakdown properties.linked, range 30d, no filters.
chart.aggregate input (trimmed):
{"chartType":"pie","interval":"day","breakdowns":[{"id":"Jv-4","name":"properties.linked"}],"globalFilters":[],"series":[{"type":"event","segment":"one_event_per_user","filters":[],"id":"EyUz","name":"game_auth_verified"}],"range":"30d","metric":"sum","limit":500}
Generated SQL (-- Aggregate Chart --):
SELECT 'game_auth_verified' as label_0, '2026-08-15 00:00:00' as date, e.properties['linked'] as label_1, count(*) as count
FROM (
SELECT DISTINCT ON (profile_id) * from events e
WHERE project_id = '<project>' AND e.name = 'game_auth_verified'
AND created_at >= toDateTime('2026-08-15 00:00:00') AND created_at <= toDateTime('2026-09-15 00:00:00')
ORDER BY profile_id, created_at DESC
) as subQuery
WHERE (project_id = '<project>') AND (e.name = 'game_auth_verified')
AND (created_at >= toDateTime('2026-08-15 00:00:00')) AND (created_at <= toDateTime('2026-09-15 00:00:00'))
GROUP BY label_1, label_0
ClickHouse error:
Code 47: Unknown expression or function identifier `e.properties` in scope SELECT ...
Root cause (packages/db/src/services/chart.service.ts)
- Breakdown SELECT expressions are always built with the events alias:
getSelectPropertyKey(breakdown.name, …, 'e') → e.properties['linked'].
- For
one_event_per_user the FROM is replaced with a subquery aliased subQuery, so e is not in scope in the outer query.
- The series path clears
sb.where to avoid e.name (comment there), but the SELECT still references e.properties. The aggregate path (chart.aggregate) clears nothing, so both e.properties and e.name are out of scope.
Suggested fix
Alias the subquery as e instead of subQuery in both places () as e). The subquery does SELECT * from events e, so e.properties[...]/e.name in the outer SELECT/WHERE resolve; the duplicated outer WHERE becomes redundant but valid. Alternatively pass no alias to getSelectPropertyKey in the one_event_per_user branch. A test case in chart-sql.test.ts for one_event_per_user + breakdown would catch this.
Any chart with a series segment
one_event_per_userand a property breakdown fails. Reproduced on currentmain(SQL below uses theDISTINCT ONform from #476).Repro
Pie chart, series: event
game_auth_verified, segment "One event per user", breakdownproperties.linked, range 30d, no filters.chart.aggregateinput (trimmed):{"chartType":"pie","interval":"day","breakdowns":[{"id":"Jv-4","name":"properties.linked"}],"globalFilters":[],"series":[{"type":"event","segment":"one_event_per_user","filters":[],"id":"EyUz","name":"game_auth_verified"}],"range":"30d","metric":"sum","limit":500}Generated SQL (
-- Aggregate Chart --):ClickHouse error:
Root cause (
packages/db/src/services/chart.service.ts)getSelectPropertyKey(breakdown.name, …, 'e')→e.properties['linked'].one_event_per_userthe FROM is replaced with a subquery aliasedsubQuery, soeis not in scope in the outer query.sb.whereto avoide.name(comment there), but the SELECT still referencese.properties. The aggregate path (chart.aggregate) clears nothing, so bothe.propertiesande.nameare out of scope.Suggested fix
Alias the subquery as
einstead ofsubQueryin both places () as e). The subquery doesSELECT *fromevents e, soe.properties[...]/e.namein the outer SELECT/WHERE resolve; the duplicated outer WHERE becomes redundant but valid. Alternatively pass no alias togetSelectPropertyKeyin theone_event_per_userbranch. A test case inchart-sql.test.tsforone_event_per_user+ breakdown would catch this.