Repository navigation
fix(funnel): qualify has_profile columns to avoid ClickHouse ILLEGAL_AGGREGATION - #671
Conversation
Session-grouped funnels select argMax(profile_id, created_at) AS profile_id and put step filters in the same WHERE. Unqualified has_profile predicates resolved to that aggregate alias and raised ClickHouse Code 184. Apply the existing events qualifier to both profile_id and device_id when provided.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Summary
Fixes #663
Session-grouped funnel queries failed with ClickHouse Code 184 when a step used the built-in
has_profilefilter.Root cause
For
funnelGroup = session_id, the funnel CTE selectsargMax(profile_id, created_at) AS profile_idand places step filter predicates in the same SELECT'sWHERE. Thehas_profilebranch ingetEventFiltersWhereClauseemitted unqualifiedprofile_id != device_id/profile_id = device_ideven when the funnel already passed theeventstable qualifier, so ClickHouse resolvedprofile_idto the aggregate alias (ILLEGAL_AGGREGATION).Change
Apply the provided events table qualifier to both columns in the
has_profilebranch (events.profile_id/events.device_id). When no qualifier is passed, behaviour is unchanged (unqualified columns).Tests
filter-where.test.ts: asserts qualified predicates fortrueandfalsewhen an alias is given, and unqualified when it is not.funnel.sql.test.ts: session-grouped funnel SQL withhas_profilemust contain qualified comparisons and must not contain unqualifiedprofile_id/device_idcomparisons in the WHERE prefilter.How tested
bun test --isolate src/modules/chart/src/filter-where.test.tsbun test --isolate src/modules/chart/src/funnel.sql.test.ts -t "has_profile with session grouping"npx ultracite checkon the touched filesbun run --filter @openpanel/core typecheckSummary by CodeRabbit