Skip to content

fix: allow sorting a report by a column not in the output - #1469

Draft
romandubovyi wants to merge 1 commit into
mainfrom
fix/sort-by-unselected-column-6768
Draft

fix: allow sorting a report by a column not in the output#1469
romandubovyi wants to merge 1 commit into
mainfrom
fix/sort-by-unselected-column-6768

Conversation

@romandubovyi

Copy link
Copy Markdown
Contributor

Problem

Configuring a report sort on a column that was not among the selected output columns failed with Output controls validation failed (SORT_COLUMN_NOT_SELECTED). Filtering already allowed hidden columns, so the two controls behaved inconsistently — you could filter by a column you didn't output, but not sort by it.

Root cause

OutputControlsValidatorService.validateSort required every sort column to be in the selected set, while filters validate against all known fields. The SQL builders (plain and blended/multi-storage) already support ORDER BY on a non-selected column for non-aggregated reports:

  • Plain builder qualifies sort to src.<col>, and the full source table is available.
  • Blended builder already adds sort columns to the CTE referencedColumns and qualifies them to main.<col> or the joined CTE.

The only place the restriction is genuinely required is aggregated (GROUP BY) reports, where ORDER BY resolves through the aggregated-alias resolver and can reference only a projected dimension or an aggregated metric.

Changes

Backend (output-controls-validator.service.ts)

  • Non-aggregated report with an explicit column selection → sort by any known column is allowed (native or joined/blended). An unknown column is still surfaced as a disconnected-column error.
  • Aggregated report (GROUP BY) → unchanged: sort must reference a projected dimension or aggregated metric.
  • No explicit column selection (SELECT * over native fields) → sort still limited to native columns (blended aliases aren't projected on that path).

Frontend (OutputSettingsDropdown / SortSection, new hasExplicitColumns prop)

  • The "Add sort by" picker offers all columns for a non-aggregated report with an explicit selection, mirroring the Filters section.
  • Aggregated reports (and the SELECT * case) keep offering only the selected output columns, so an invalid sort target is never presented.

Multi-storage

Verified against the blended query builder: sort columns are materialized into the relevant CTE and qualified correctly, so sorting by a non-selected joined column works end to end; the SELECT * + blended combination is still rejected as before.

Tests

  • Backend unit: added cases for sort on a non-selected native/blended column (accepted) and on a non-projected column in an aggregated report (rejected). Full suite: 175 passing.
  • Backend e2e (output-controls): updated to accept the previously-rejected sort and added an aggregated-report rejection case.
  • Frontend: OutputSettingsDropdown and ReportColumnPicker suites passing; tsc --noEmit clean.
  • Added a changeset.

Report sorting no longer requires the sorted column to be among the
selected output columns. A non-aggregated report can now sort by any
known column of its data mart (including joined/blended columns when the
report has an explicit column selection), the same way filters already
work — so the "Output controls validation failed" error no longer fires
for a valid sort on a hidden column.

Aggregated (GROUP BY) reports are unchanged: they can still sort only by
a projected dimension or an aggregated metric. The frontend sort picker
now offers all columns for non-aggregated reports with an explicit
selection, and stays limited to the selected columns otherwise.
@romandubovyi romandubovyi self-assigned this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant