Skip to content

Commit f0e3fbf

Browse files
authored
get all columns in union for funnels and charts (#137)
1 parent 331079b commit f0e3fbf

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

packages/db/src/services/conversion.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
getCohortCteName,
1111
getCohortAlias,
1212
buildCohortMembershipQuery,
13+
getMaterializedColumns,
1314
} from './chart.service';
1415
import { onlyReportEvents } from './reports.service';
1516
import { getCustomEventByName, expandCustomEventToSQL } from './custom-event.service';
@@ -46,6 +47,13 @@ export class ConversionService {
4647
};
4748
}
4849

50+
// Get materialized columns to ensure UNION compatibility
51+
const materializedColumns = await getMaterializedColumns();
52+
const materializedColumnNames = Object.values(materializedColumns);
53+
const materializedColumnsSelect = materializedColumnNames.length > 0
54+
? `, ${materializedColumnNames.join(', ')}`
55+
: '';
56+
4957
// Build CTEs for custom events
5058
const ctes: string[] = [];
5159
const baseWhere = [
@@ -80,8 +88,9 @@ export class ConversionService {
8088
if (customEvents[index]) {
8189
unionParts.push(`SELECT * FROM custom_event_${index}`);
8290
} else {
91+
// Regular event - include materialized columns to match custom events
8392
unionParts.push(`
84-
SELECT * FROM ${TABLE_NAMES.events}
93+
SELECT *${materializedColumnsSelect} FROM ${TABLE_NAMES.events}
8594
WHERE project_id = '${projectId}'
8695
AND name = '${event.name}'
8796
AND created_at BETWEEN toDateTime('${startDate}') AND toDateTime('${endDate}')

packages/db/src/services/funnel.service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
getCohortCteName,
1818
getCohortAlias,
1919
buildCohortMembershipQuery,
20+
getMaterializedColumns,
2021
} from './chart.service';
2122
import { onlyReportEvents } from './reports.service';
2223
import {
@@ -57,6 +58,13 @@ export class FunnelService {
5758
};
5859
}
5960

61+
// Get materialized columns to ensure UNION compatibility
62+
const materializedColumns = await getMaterializedColumns();
63+
const materializedColumnNames = Object.values(materializedColumns);
64+
const materializedColumnsSelect = materializedColumnNames.length > 0
65+
? `, ${materializedColumnNames.join(', ')}`
66+
: '';
67+
6068
// Build CTEs for custom events
6169
const withClauses: Array<{ name: string; query: any }> = [];
6270
const baseWhere = [
@@ -90,9 +98,9 @@ export class FunnelService {
9098

9199
unionParts.push(`SELECT * FROM ${cteName}`);
92100
} else {
93-
// Regular event - select directly
101+
// Regular event - include materialized columns to match custom events
94102
unionParts.push(`
95-
SELECT * FROM ${TABLE_NAMES.events}
103+
SELECT *${materializedColumnsSelect} FROM ${TABLE_NAMES.events}
96104
WHERE project_id = '${projectId}'
97105
AND name = '${event.name}'
98106
AND created_at BETWEEN toDateTime('${startDate}') AND toDateTime('${endDate}')

0 commit comments

Comments
 (0)