fix: chart preview aggregation with pagination and sorting#1385
Draft
sentry[bot] wants to merge 1 commit into
Draft
fix: chart preview aggregation with pagination and sorting#1385sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
Author
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1385 +/- ##
=======================================
Coverage 58.66% 58.66%
=======================================
Files 132 132
Lines 15690 15690
=======================================
Hits 9205 9205
Misses 6485 6485 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses issue DALGO-BACKEND-26C, where users encountered a
ProgrammingError: UndefinedColumnwhen viewing chart data previews with pagination and sorting applied to aggregated metrics (e.g.,COUNT(*)).Root Cause:
The
build_chart_queryfunction incharts_service.pywas structured such that when pagination was enabled, it would wrap the base table in aSELECT *subquery. However, the subsequent logic responsible for adding aggregation columns (likeCOUNT(*) AS "count_all_Total Count") andGROUP BYclauses was nested within theelseblock (the non-paginated path). This meant that for paginated queries, no aggregation columns were ever added to the main query.When chart-level sorting was then applied, it would correctly translate the user-facing metric alias (e.g., "Total Count") into its internal SQL alias (e.g.,
"count_all_Total Count") and attempt toORDER BYthis column. Since the column did not exist in theSELECTclause of the paginated query, aProgrammingError: UndefinedColumnoccurred.Solution:
To fix this, the chart-type-specific query building logic (which includes adding dimensions, metrics, and grouping) has been un-indented from the
elseblock. This ensures that this core aggregation and column selection logic is applied universally, regardless of whether the initial data source is the raw table or a paginated subquery. As a result, when pagination is enabled, the aggregation columns will now be correctly added to the query, allowing sorting by these columns to succeed.Fixes DALGO-BACKEND-26C