Skip to content

Oracle: Support KEEP (DENSE_RANK FIRST | LAST ...) on aggregate functions - #3094

Open
BenSatori wants to merge 2 commits into
apache:mainfrom
BenSatori:oracle-gap-25-keep-dense-rank
Open

BenSatori wants to merge 2 commits into
apache:mainfrom
BenSatori:oracle-gap-25-keep-dense-rank

Conversation

@BenSatori

@BenSatori BenSatori commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Dialects: Oracle, Generic

SELECT MAX(c.contact_name) KEEP (DENSE_RANK LAST ORDER BY c.id) AS metric FROM customers c currently fails with:
Expected: end of statement, found: (

Oracle's FIRST/LAST aggregates take a KEEP (DENSE_RANK { FIRST | LAST } ORDER BY ...) clause after the function call, optionally followed by OVER (...). This PR adds Function::keep: Option<Box<KeepClause>> (with KeepClause and KeepRank), parsed when Dialect::supports_aggregate_keep_clause() is true (Oracle and Generic). KEEP is only treated as the clause when followed by (, so keep stays usable as an identifier or alias.

Syntax reference: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/FIRST.html

API change: Function gains a keep field, so code constructing Function literals needs keep: None.

Note on stack usage: Function is the largest Expr variant, so this grows Expr from 328 to 336 bytes. On macOS arm64 debug builds that is enough to push test_parentheses_overflow (sqlparser_snowflake) and parse_table_factor_paren_chain_no_exponential_blowup (sqlparser_common) past the default 2 MiB test-thread stack; upstream main already passes them with only ~16-32 KiB to spare below the recursive crate's 128 KiB red zone. Any new field on Function would do the same. CI (Linux) passes both tests. Happy to send a separate PR to widen that margin (e.g. boxing Function::over) if you'd prefer.

Fuzzed with fuzz_parse_sql and fuzz_parse_roundtrip for 60 seconds each, no panics. Seed: fuzz/fuzz_seeds/oracle_aggregate_keep_clause.sql.

This PR was written with AI assistance (Claude Code). I reviewed every line and can explain each change.

🤖 Generated with Claude Code

…ions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.98246% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.73%. Comparing base (140ff04) to head (6d9c7b2).

Files with missing lines Patch % Lines
src/parser/mod.rs 90.90% 0 Missing and 2 partials ⚠️
src/ast/mod.rs 92.85% 0 Missing and 1 partial ⚠️
src/ast/spans.rs 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3094      +/-   ##
==========================================
+ Coverage   83.71%   83.73%   +0.02%     
==========================================
  Files          42       42              
  Lines       35908    35964      +56     
  Branches    35908    35964      +56     
==========================================
+ Hits        30059    30116      +57     
+ Misses       2412     2407       -5     
- Partials     3437     3441       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BenSatori
BenSatori marked this pull request as ready for review December 3, 2026 11:38
@yoavcloud
yoavcloud self-requested a review December 3, 2026 11:43
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants