Skip to content

Fix aggregate queries without explicit grouping#3980

Open
caglareker wants to merge 2 commits intoFoundationDB:mainfrom
caglareker:fix/issue-3979-aggregate-continued-queries-without-an-e
Open

Fix aggregate queries without explicit grouping#3980
caglareker wants to merge 2 commits intoFoundationDB:mainfrom
caglareker:fix/issue-3979-aggregate-continued-queries-without-an-e

Conversation

@caglareker
Copy link

Fixes #3979

When continuing an aggregate query without an explicit GROUP BY clause, the code attempted to deserialize a group key even when no grouping key value existed, causing incorrect results.

Add null checks to handle the case where groupingKeyValue is null:

  • Skip group key deserialization in the constructor if there's no explicit grouping
  • Only include the group key in the serialized partial aggregation result when one exists

This ensures continued aggregate queries without grouping work correctly when resuming from a cursor.

When continuing an aggregate query without an explicit GROUP BY clause,
the code attempted to deserialize a group key even when groupingKeyValue
was null, causing incorrect results.

Add null checks to skip group key handling when there is no explicit
grouping, ensuring continued queries work correctly.
@alecgrieser alecgrieser added bug fix Change that fixes a bug labels Mar 5, 2026
Copy link
Collaborator

@alecgrieser alecgrieser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! It seems like this could use a regression test covering the error case and then showing that it has been fixed by this change. I believe @hazefully had created a test case that showed this that used the yaml-tests framework.

The yaml-tests directory contains a bunch of queries, and it enables the queries to be executed both against the most recent server version but also against older versions in order to prevent against unexpected cross-version incompatibility problems.

The general process for creating a new file is to make a new file in yaml-tests/src/test/resources with your test case, and then to add a new method to YamlIntegrationTests that runs the tests for that file. You can look at some of the others (like, say, aggregate-index-tests.yamsql) to see how the file is formatted, but it allows the user to define a test schema and then queries that execute against it. I believe this bug only gets hit if an internal limit is hit, so IIRC, @hazefully had set the EXECUTION_SCANNED_ROWS_LIMIT option in the file in order to create a showcasing test case. (For an example of how we set connection options, you can look at, say, case-sensitivity.yamsql.)

There may be other ways to write a test for this. For example, FDBStreamAggregationTest has a bunch of other tests for the streaming aggregate code. It may be that we can add a test there and get more-or-less the same coverage

@caglareker
Copy link
Author

added a yaml-tests case for ungrouped aggregate queries with continuations. uses maxRows=1 to force the continuation path that was hitting the NPE.

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

Labels

bug fix Change that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Aggregate continued queries without an explicit group have incorrect results

2 participants