Skip to content

: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.

feat(insights): allow multiple breakdowns for data warehouse trends (#56905)

Thomas Obermüllerf7c80a762a03
diff --git a/frontend/src/lib/components/Cards/InsightCard/InsightDetails.tsx b/frontend/src/lib/components/Cards/InsightCard/InsightDetails.tsx
index 0752fb84d804..66818ab8fc99 100644
--- a/frontend/src/lib/components/Cards/InsightCard/InsightDetails.tsx
+++ b/frontend/src/lib/components/Cards/InsightCard/InsightDetails.tsx
@@ -389,7 +389,7 @@ export function PropertiesIgnoredWarning(): JSX.Element {
export function BreakdownIgnoredWarning(): JSX.Element {
return (
<InsightDetailSectionDisplay icon={<IconSort />} label="Breakdown by">
- <Tooltip title="Breakdown overrides are not applied. Insights with a data warehouse series only support a single data warehouse property breakdown.">
+ <Tooltip title="Breakdown overrides are not applied. Insights with a data warehouse series only support data warehouse property and HogQL breakdowns.">
<div className="flex items-center gap-1 text-warning italic">
<IconWarning /> Breakdown overrides ignored (data warehouse series).
</div>
diff --git a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.test.ts b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.test.ts
index 2b8df07e552e..95a7f8dc6bfb 100644
--- a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.test.ts
+++ b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.test.ts
@@ -296,7 +296,7 @@ describe('taxonomicBreakdownFilterLogic', () => {
})
})
- it('only one data warehouse breakdown is allowed', async () => {
+ it('only one data warehouse person property breakdown is allowed', async () => {
logic = taxonomicBreakdownFilterLogic(
makeProps({
breakdownFilter: {
@@ -309,18 +309,24 @@ describe('taxonomicBreakdownFilterLogic', () => {
await expectLogic(logic).toMatchValues({
addBreakdownDisabledReason: expect.stringContaining('single breakdown'),
})
+ })
- logic = taxonomicBreakdownFilterLogic(
- makeProps({
- breakdownFilter: {
- breakdown_type: 'data_warehouse',
- breakdown: 'prop',
- },
- })
- )
+ it.each<[string, breakdownLogic.TaxonomicBreakdownFilterLogicProps['breakdownFilter']]>([
+ ['legacy single data warehouse breakdown', { breakdown_type: 'data_warehouse', breakdown: 'prop' }],
+ [
+ 'multi data warehouse breakdowns',
+ {
+ breakdowns: [
+ { type: 'data_warehouse', property: 'prop1' },
+ { type: 'data_warehouse', property: 'prop2' },
+ ],
+ },
+ ],
+ ])('multiple data warehouse breakdowns are allowed: %s', async (_label, breakdownFilter) => {
+ logic = taxonomicBreakdownFilterLogic(makeProps({ breakdownFilter }))
logic.mount()
await expectLogic(logic).toMatchValues({
- addBreakdownDisabledReason: expect.stringContaining('single breakdown'),
+ addBreakdownDisabledReason: null,
})
})
@@ -889,7 +895,7 @@ describe('taxonomicBreakdownFilterLogic', () => {
})
})
- it('addBreakdown: does not migrate a data warehouse properties breakdown', async () => {
+ it('addBreakdown: migrates a data warehouse properties breakdown to multi-breakdowns', async () => {
logic = taxonomicBreakdownFilterLogic(
makeProps({
breakdownFilter: {
@@ -910,8 +916,15 @@ describe('taxonomicBreakdownFilterLogic', () => {
}).toFinishListeners()
expect(updateBreakdownFilter).toHaveBeenCalledWith({
- breakdown_type: 'data_warehouse',
- breakdown: 'new_prop',
+ breakdown: undefined,
+ breakdown_type: undefined,
+ breakdown_histogram_bin_count: undefined,
+ breakdown_normalize_url: undefined,
+ breakdown_group_type_index: undefined,
+ breakdowns: [
+ { type: 'data_warehouse', property: 'prop' },
+ { type: 'data_warehouse', property: 'new_prop' },
+ ],
})
})
@@ -941,8 +954,9 @@ describe('taxonomicBreakdownFilterLogic', () => {
})
})
- // In the UI it's not possible to add a second breakdown to a data warehouse query, but just in case.
- it('addBreakdown: does add multiple breakdowns when there is a data warehouse breakdown', async () => {
+ // `data_warehouse_person_property` still only supports a single breakdown — the UI gates this in
+ // `addBreakdownDisabledReason`. This test covers the defensive path if it ever does fire.
+ it('addBreakdown: does add multiple breakdowns when there is a data warehouse person property breakdown', async () => {
logic = taxonomicBreakdownFilterLogic(
makeProps({
breakdownFilter: {
diff --git a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts
index af83004586a7..0cb5c1f6884b 100644
--- a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts
+++ b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterLogic.ts
@@ -168,12 +168,7 @@ export const taxonomicBreakdownFilterLogic = kea<taxonomicBreakdownFilterLogicTy
isTrends,
isSingleSeriesDefinition
): string | null => {
- // Multiple breakdowns don't yet support the data warehouse, so it fallbacks to a single breakdown.
- if (
- isMultipleBreakdownsEnabled &&
- !hasDataWarehouseSeries &&
- (!breakdown_type || isMultipleBreakdownType(breakdown_type))
- ) {
+ if (isMultipleBreakdownsEnabled && (!breakdown_type || isMultipleBreakdownType(breakdown_type))) {
if (!!breakdowns && breakdowns.length >= MAX_TRENDS_BREAKDOWNS) {
return `You can break down trends by up to ${MAX_TRENDS_BREAKDOWNS} properties. Remove one to add another.`
}
diff --git a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterUtils.ts b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterUtils.ts
index 7c94506cac2e..f69668c87c3f 100644
--- a/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterUtils.ts
+++ b/frontend/src/scenes/insights/filters/BreakdownFilter/taxonomicBreakdownFilterUtils.ts
@@ -12,6 +12,14 @@ export const isURLNormalizeable = (propertyName: string): boolean => {
}
export function isMultipleBreakdownType(breakdownType?: BreakdownType | null): breakdownType is MultipleBreakdownType {
- const types: MultipleBreakdownType[] = ['person', 'event', 'event_metadata', 'group', 'session', 'hogql']
+ const types: MultipleBreakdownType[] = [
+ 'person',
+ 'event',
+ 'event_metadata',
+ 'group',
+ 'session',
+ 'hogql',
+ 'data_warehouse',
+ ]
return !!breakdownType && (types as string[]).includes(breakdownType)
}
diff --git a/frontend/src/scenes/insights/utils.tsx b/frontend/src/scenes/insights/utils.tsx
index 1e4ce7900f42..66c711599baf 100644
--- a/frontend/src/scenes/insights/utils.tsx
+++ b/frontend/src/scenes/insights/utils.tsx
@@ -829,7 +829,7 @@ export const getOverrideWarningPropsForButton = (
}
/** Checks for breakdown features that are unsupported by trend insights with a
- * data warehouse series. */
+ * data warehouse series. Mirrors backend `ValidateDataWarehouseBreakdown`. */
export const hasUnsupportedBreakdownForDataWarehouseTrends = (
filtersOverride: DashboardFilter | TileFilters | null | undefined
): boolean => {
@@ -839,10 +839,16 @@ export const hasUnsupportedBreakdownForDataWarehouseTrends = (
return false
}
+ const supportedTypes = new Set(['data_warehouse', 'hogql'])
+
+ if (breakdownFilter.breakdowns?.length) {
+ return breakdownFilter.breakdowns.some((b) => !b.type || !supportedTypes.has(b.type))
+ }
+
return !!(
- breakdownFilter.breakdowns?.length ||
- breakdownFilter.breakdown_type !== 'data_warehouse' ||
!breakdownFilter.breakdown ||
- Array.isArray(breakdownFilter.breakdown)
+ Array.isArray(breakdownFilter.breakdown) ||
+ !breakdownFilter.breakdown_type ||
+ !supportedTypes.has(breakdownFilter.breakdown_type)
)
}
diff --git a/posthog/hogql_queries/insights/trends/trends_query_runner.py b/posthog/hogql_queries/insights/trends/trends_query_runner.py
index d3ecdb68ac65..9290bdd75d25 100644
--- a/posthog/hogql_queries/insights/trends/trends_query_runner.py
+++ b/posthog/hogql_queries/insights/trends/trends_query_runner.py
@@ -1118,7 +1118,7 @@ class TrendsQueryRunner(AnalyticsQueryRunner[TrendsQueryResponse]):
return False
if isinstance(self.query.series[0], DataWarehouseNode) and breakdown_type == "data_warehouse":
- series = self.query.series[0] # only one series when data warehouse is active
+ series = self.query.series[0]
table_or_view = get_view_or_table_by_name(self.team, series.table_name)