GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [SQL] Support the PostgresSQL extension `DISTINCT ON` by mihaibudiu · Pull Request #7904 · feldera/feldera

Conversation

@mihaibudiu

@mihaibudiu mihaibudiu commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Linked Issue

Fixes #7644

This branch is rebased already on #6599 which advances the Calcite version, and which is supposed to merge first.
Calcite already rewrites DISTINCT ON into other operators we support; this PR just enables the transformation and adds tests.

Checklist

  • Unit tests added/updated
  • Documentation updated

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mythical-fred-oss[bot]
mythical-fred-oss Bot reviewed Nov 9, 2026
View reviewed changes
Comment thread docs.feldera.com/docs/sql/grammar.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mythical-fred-oss

mythical-fred-oss Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

What I ran: ./build.sh (with Calcite at 4bf922b), then mvn test -Dtest=TopKTests,FloatingPointEqualityTests,NegativeParserTests,ArrayTests,DocumentationTests and pre-commit run on the changed files. pre-commit passes, and so do all the new tests.

bug (high): NegativeParserTests.errorTest fails. The Calcite bump changes what "This is not SQL" reports. It used to be Non-query expression encountered in illegal context; now it is Encountered "not SQL". Was expecting one of: .... I set isDistinctOnAllowed() back to false and the test still failed, so the bump causes it, not DISTINCT ON. It probably affects #6599 too. Please update the test's expected message.

missing (medium): test coverage. I wrote these QA cases as incremental tests (StreamingTestBase). None are in the PR:

Case Result
Insert a better row (old row retracted), delete it (runner-up comes back), delete a group's last row ✅
Expression key DISTINCT ON (a % 2) ✅
Multiple keys (a, b) ✅
Key is a SELECT alias ✅
DISTINCT ON over GROUP BY / aggregate ✅
ORDER BY has only the key (every row ties): one row per group ✅
Keys are not a prefix of ORDER BY: rejected ✅ (no negative test in PR)
ORDER BY 1, 2 ordinals, or keys in a different order ❌ rejected; see inline comment

The PR's distinctOn tests only run in the non-incremental SqlIoTest, so nothing checks retractions. I suggest adding at least the retraction case to TopKUnusedFieldsIncrementalTests or a StreamingTestBase class:

@Test
public void distinctOnIncremental() {
    var ccs = this.getCCS("""
            CREATE TABLE T(a INT, b INT, c INT);
            CREATE VIEW V AS SELECT DISTINCT ON (a) a, b, c FROM T ORDER BY a, b DESC;""");
    ccs.step("INSERT INTO T VALUES (1, 1, 10), (1, 2, 20), (2, 5, 30);", """
             a | b | c  | weight
            ---------------------
             1 | 2 | 20 | 1
             2 | 5 | 30 | 1""");
    ccs.step("INSERT INTO T VALUES (1, 3, 40);", """
             a | b | c  | weight
            ---------------------
             1 | 2 | 20 | -1
             1 | 3 | 40 | 1""");
    ccs.step("REMOVE FROM T VALUES (1, 3, 40);", """
             a | b | c  | weight
            ---------------------
             1 | 3 | 40 | -1
             1 | 2 | 20 | 1""");
}

Also, this PR still contains the UNNEST commit from #6599, so it should be rebased once #6599 merges.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mihaibudiu
mihaibudiu force-pushed the issue7644 branch from 1329c63 to 6bbfd6d Compare November 10, 2026 00:40
mihaibudiu added 2 commits November 10, 2026 11:15
@mihaibudiu
[SQL] Compile '1 = ROW_NUMBER() ...' as a TopK, like 'ROW_NUMBER() ..…
1524e7d
…. = 1'

Signed-off-by: Mihai Budiu <[email protected]>
@mihaibudiu
[SQL] Support SELECT DISTINCT ON
60fface
Fixes #7644

Signed-off-by: Mihai Budiu <[email protected]>
@mihaibudiu
mihaibudiu force-pushed the issue7644 branch from 6bbfd6d to 60fface Compare November 10, 2026 19:17

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mythical-fred-oss mythical-fred-oss[bot] mythical-fred-oss[bot] left review comments

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[SQL] Support DISTINCT ON window queries

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@mihaibudiu
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.