feat(multi_stage): add median measure type with PERCENTILE_CONT support#10736
Draft
TheRoot-1 wants to merge 1 commit intocube-js:masterfrom
Draft
feat(multi_stage): add median measure type with PERCENTILE_CONT support#10736TheRoot-1 wants to merge 1 commit intocube-js:masterfrom
TheRoot-1 wants to merge 1 commit intocube-js:masterfrom
Conversation
Adds `median` as a valid multi_stage measure type, rendering as `PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY <sql>)` in both the JS schema-compiler path and the Tesseract native SQL planner. JS changes: - CubeValidator: add 'median' to multiStageMeasureType allowlist - BaseQuery: render PERCENTILE_CONT in multi_stage and general aggregation paths Tesseract changes: - MeasureKind::Median variant with full dependency/SQL wiring - MultiStageMedianNode SQL node for PERCENTILE_CONT rendering - MultiStageInodeMemberType::Median planner variant - MultiStageCalculationWindowFunction::Median physical plan variant Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
Adds
medianas a supportedmulti_stagemeasure type, rendered as an ordered-set aggregate (PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY ...)). This is the first half of #10560 —dense_rankis not yet implemented and will come as a follow-up (or separate PR) depending on review feedback.Without this, users hit a schema validation error (
medianis not a validmultiStageMeasureType) and have no runtime-filter-respecting way to compute medians — they're forced into static subqueries that ignore filters.What's included
Schema compiler (JS planner):
mediantype inmultiStageMeasureTypevalidatorBaseQuery.jsthat emitsPERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY <inner_measure>)against the correct CTE referenceTesseract (Rust planner):
MultiStageMedianNodesql nodeSqlNodesFactorymeasure_kinds/mod.rscalculation.rs,multi_stage_measure_calculation.rs)Example
Generated SQL (Postgres):
Test plan
cubejs-schema-compilerunit tests pass (test/unit/base-query.test.ts,test/unit/cube-validator.test.ts)cubesqlplannerfull suite: 876 passed, 0 failedtest/integration/postgres/multi-stage.test.tsbut haven't run it locally)dense_rankNotes
medianonly.dense_rank(the other half of feat(multi_stage): support median (PERCENTILE_CONT) and dense_rank as multi_stage measure types #10560) is intentionally out of scope for this PR; happy to do it as a follow-up once this shape is approved.Closes part of #10560