Openpanel-dev / Openpanel-dev/openpanel

`one_event_per_user` segment + breakdown fails: `Unknown expression or function identifier e.properties`

Open Beginner friendly
#502 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7k
Forks
481
Avg merge
1d 3h
Merged PRs (30d)
21

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/db/src/services/chart.service.ts, inspect the one_event_per_user SQL branches, and run the relevant chart SQL tests. Add coverage in chart-sql.test.ts for one_event_per_user with a property breakdown; done means the generated query runs without the unknown e.properties or e.name error and the expected breakdown is returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
clickhouse, typescript
Domain
backend, databases, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.