feat(sql): implement percent_rank() window function#6712
feat(sql): implement percent_rank() window function#6712bluestreak01 merged 5 commits intomasterfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
WalkthroughThe PR introduces a new PercentRankFunctionFactory implementing the percent_rank() window function with three execution modes (with partition and order, with order only, with neither), removes deprecated window function factories from the registry, and adds comprehensive test coverage for the new function. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@CodeRabbit can you review this window function implementation pls? |
🧩 Analysis chain
🏁 Script executed: Length of output: 16091 🏁 Script executed: Length of output: 26362 🏁 Script executed: Length of output: 272 🏁 Script executed: Length of output: 18703
✅ Strengths
📝 Minor ObservationThe
However, this is consistent with 🎯 VerdictThis is production-ready code. The implementation is clean, efficient, follows established patterns, and has excellent test coverage. The logic for handling partitions, peer groups, and edge cases is all correct. Great work! 🚀 🧠 Learnings used✅ Actions performedReview triggered.
|
|
@CodeRabbit i added "order by" if exists to the plan. Please review. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 16446
✅ Changes Look PerfectThe ORDER BY clause is now properly included in the plan output:
The 🧠 Learnings used |
[PR Coverage check]😍 pass : 156 / 166 (93.98%) file detail
|
…tion (#350) ## Summary - Add documentation for the new `percent_rank()` window function ([questdb/questdb#6712](questdb/questdb#6712)) - Comprehensive improvements to all window functions documentation for better human and LLM comprehension ## Changes ### New Content - **percent_rank()** documentation with syntax, description, use cases, and examples - **Ranking functions comparison table** showing differences between `row_number`, `rank`, `dense_rank`, and `percent_rank` - **Practical use cases** for all 14 window functions explaining when and why to use each ### Documentation Quality Improvements - Added **return types** to all function signatures (e.g., `double`, `long`, "same type as input") - Added **supported data types** for aggregate functions (`short`, `int`, `long`, `float`, `double`) - Updated **keywords and descriptions** in frontmatter for better searchability - Added note about **unsupported functions** (`ntile()`, `cume_dist()`) ### Example Fixes - Updated all examples to use **TICK expressions** (`'[$today]'`) instead of `today()` - Fixed column names to match **demo schema** (`amount` instead of `volume`, `BTC-USDT` instead of `BTC-USD`) - Added **timestamp** column to all SELECT examples for consistency - Added **demo tags** and WHERE filters to all runnable examples - Fixed VWAP example CTE reference ## Test plan - [x] All SQL examples validated against demo.questdb.io (34 queries tested) - [x] `yarn build` succeeds - [x] Preview server renders correctly 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.5 <[email protected]>
Summary
percent_rank()window function(rank - 1) / (total_rows - 1)Implementation
Three inner classes handle different use cases:
PercentRankNoOrderFunction (ZERO_PASS): For
percent_rank() over ()orpercent_rank() over (partition by x)without ORDER BY. All rows are peers with rank 1, so percent_rank = 0 for all rows.PercentRankFunction (TWO_PASS): For
percent_rank() over (order by x)without PARTITION BY. Uses two passes to first compute ranks, then calculate percent_rank using total row count.PercentRankOverPartitionFunction (TWO_PASS): For
percent_rank() over (partition by x order by y). Tracks per-partition row counts in a map to compute percent_rank within each partition.Test plan
percent_rank() over ()returns 0 for all rowspercent_rank() over (partition by x)returns 0 for all rowspercent_rank() over (order by x)computes correct valuespercent_rank() over (partition by x order by y)computes correct values per partition🤖 Generated with Claude Code