: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(sql-editor): allow 10k and 50k rows in pivot queries (#108434)
Marius Andraab10a7a559ac
diff --git a/frontend/src/scenes/data-warehouse/editor/bi/BIEditor.tsx b/frontend/src/scenes/data-warehouse/editor/bi/BIEditor.tsxindex ab059c0705fb..582ff1e12b98 100644--- a/frontend/src/scenes/data-warehouse/editor/bi/BIEditor.tsx+++ b/frontend/src/scenes/data-warehouse/editor/bi/BIEditor.tsx@@ -39,7 +39,6 @@ import {BIShelf,BIField,BISortDirection,- PIVOT_TABLE_QUERY_LIMIT,getBIDataSourceKey,isDateTimeBIField,isNumericBIField,@@ -131,10 +130,6 @@ export function BIEditor({ tabId }: { tabId: string }): JSX.Element {setValueAggregation,setValueCustomExpression,} = useActions(logic)- const limitOptions =- config.chartType === ChartDisplayType.TwoDimensionalHeatmap- ? LIMIT_OPTIONS.filter(({ value }) => value <= PIVOT_TABLE_QUERY_LIMIT)- : LIMIT_OPTIONSreturn (<div@@ -197,7 +192,7 @@ export function BIEditor({ tabId }: { tabId: string }): JSX.Element {/><LemonSelectvalue={config.limit}- options={limitOptions}+ options={LIMIT_OPTIONS}onChange={setLimit}renderButtonContent={(option) => `Limit: ${option?.label ?? config.limit}`}aria-label="Query row limit"diff --git a/frontend/src/scenes/data-warehouse/editor/bi/biEditorTypes.test.ts b/frontend/src/scenes/data-warehouse/editor/bi/biEditorTypes.test.tsindex ad56a2bbbe01..b238d655486e 100644--- a/frontend/src/scenes/data-warehouse/editor/bi/biEditorTypes.test.ts+++ b/frontend/src/scenes/data-warehouse/editor/bi/biEditorTypes.test.ts@@ -108,32 +108,35 @@ describe('BI editor query generation', () => {expect(result?.query).toContain('count(*) AS count')})- it('maps every BI row and column dimension to pivot table axes', () => {- const result = buildBIQuery({- source: { table: 'events' },- chartType: ChartDisplayType.TwoDimensionalHeatmap,- rows: [eventField, timestampField],- columns: [browserField, countryField],- values: [{ field: revenueField, aggregation: 'sum' }],- filters: [],- limit: 50000,- })+ it.each([100, 1000, 10000, 50000] as const)(+ 'maps every BI row and column dimension to pivot table axes with limit %i',+ (limit) => {+ const result = buildBIQuery({+ source: { table: 'events' },+ chartType: ChartDisplayType.TwoDimensionalHeatmap,+ rows: [eventField, timestampField],+ columns: [browserField, countryField],+ values: [{ field: revenueField, aggregation: 'sum' }],+ filters: [],+ limit,+ })- expect(result?.query).toContain('toJSONString(tuple(event, timestamp)) AS bi_rows')- expect(result?.query).toContain(- 'toJSONString(tuple(properties.$browser, properties.$geoip_country_name)) AS bi_columns'- )- expect(result?.query).toContain('LIMIT 1000')- expect(result?.node.chartSettings).toEqual({- heatmap: {- xAxisColumn: 'bi_columns',- yAxisColumn: 'bi_rows',- valueColumn: 'sum_revenue',- xAxisLabel: 'browser / country',- yAxisLabel: 'event / timestamp',- },- })- })+ expect(result?.query).toContain('toJSONString(tuple(event, timestamp)) AS bi_rows')+ expect(result?.query).toContain(+ 'toJSONString(tuple(properties.$browser, properties.$geoip_country_name)) AS bi_columns'+ )+ expect(result?.query).toContain(`LIMIT ${limit}`)+ expect(result?.node.chartSettings).toEqual({+ heatmap: {+ xAxisColumn: 'bi_columns',+ yAxisColumn: 'bi_rows',+ valueColumn: 'sum_revenue',+ xAxisLabel: 'browser / country',+ yAxisLabel: 'event / timestamp',+ },+ })+ }+ )it('ignores blank shelf fields until they are configured', () => {const blankField: BIField = {diff --git a/frontend/src/scenes/data-warehouse/editor/bi/biEditorTypes.ts b/frontend/src/scenes/data-warehouse/editor/bi/biEditorTypes.tsindex f117437fe741..a601e3f51c6d 100644--- a/frontend/src/scenes/data-warehouse/editor/bi/biEditorTypes.ts+++ b/frontend/src/scenes/data-warehouse/editor/bi/biEditorTypes.ts@@ -17,8 +17,6 @@ export const BI_QUERY_LIMITS = [100, 1000, 10000, 50000] as constexport type BIQueryLimit = (typeof BI_QUERY_LIMITS)[number]-export const PIVOT_TABLE_QUERY_LIMIT: BIQueryLimit = 1000-export type BISortDirection = 'asc' | 'desc'export interface BISort {@@ -115,10 +113,6 @@ export const DEFAULT_BI_CONFIG: BIConfig = {export function normalizeBIConfig(config: BIConfig): BIConfig {let normalized = config- if (normalized.chartType === ChartDisplayType.TwoDimensionalHeatmap && normalized.limit > PIVOT_TABLE_QUERY_LIMIT) {- normalized = { ...normalized, limit: PIVOT_TABLE_QUERY_LIMIT }- }-const sort = normalized.sortif (sort && !getBISortOptions(normalized).some((option) => option.key === sort.key)) {normalized = { ...normalized, sort: null }diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.tsindex cd5060828b71..6a731247650a 100644--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts@@ -2189,7 +2189,6 @@ describe('sqlEditorLogic', () => {chartType: ChartDisplayType.TwoDimensionalHeatmap,limit: 50000,}- const restoredConfig: BIConfig = { ...persistedConfig, limit: 1000 }router.actions.push(urls.sqlEditor(), undefined, {q: "SELECT event, count(*) FROM events WHERE event = 'signup' GROUP BY event",@@ -2201,17 +2200,17 @@ describe('sqlEditorLogic', () => {.toDispatchActions(['createTab', 'updateTab']).toMatchValues({activeTab: partial({- biEditorState: { editorView: BIEditorView.BI, config: restoredConfig },+ biEditorState: { editorView: BIEditorView.BI, config: persistedConfig },}),})- await expectLogic(biLogic).toMatchValues({ editorView: BIEditorView.BI, config: restoredConfig })+ await expectLogic(biLogic).toMatchValues({ editorView: BIEditorView.BI, config: persistedConfig })await expectLogic(biLogic, () => biLogic.actions.setFilterValue(0, 'purchase')).toFinishAllListeners()expect(router.values.hashParams.mode).toEqual(BIEditorView.BI)expect(router.values.hashParams.bi).toEqual({- ...restoredConfig,- filters: [{ ...restoredConfig.filters[0], value: 'purchase' }],+ ...persistedConfig,+ filters: [{ ...persistedConfig.filters[0], value: 'purchase' }],})biLogic.unmount()@@ -2276,12 +2275,12 @@ describe('sqlEditorLogic', () => {biLogic.actions.setChartType(ChartDisplayType.TwoDimensionalHeatmap)).toFinishAllListeners()- expect(biLogic.values.config.limit).toBe(1000)- expect(logic.values.queryInput).toContain('LIMIT 1000')+ expect(biLogic.values.config.limit).toBe(50000)+ expect(logic.values.queryInput).toContain('LIMIT 50000')expect(router.values.hashParams.bi).toEqual({...config,chartType: ChartDisplayType.TwoDimensionalHeatmap,- limit: 1000,+ limit: 50000,})biLogic.unmount()