Skip to content

Add $first accumulator tests#228

Open
alinaliBQ wants to merge 10 commits into
documentdb:mainfrom
alinaliBQ:first
Open

Add $first accumulator tests#228
alinaliBQ wants to merge 10 commits into
documentdb:mainfrom
alinaliBQ:first

Conversation

@alinaliBQ
Copy link
Copy Markdown
Contributor

This change adds tests for the $first accumulator operator.

Add accumulator operator tests for $first. Tests database $first behavior, output collection, syntax, and expected errors.
Integration tests are in documentdb_tests/compatibility/tests/core/operator/accumulators/test_accumulators_first_integration.py

@alinaliBQ alinaliBQ marked this pull request as ready for review May 22, 2026 21:31
@alinaliBQ alinaliBQ requested a review from a team as a code owner May 22, 2026 21:31
@documentdb-triage-tool documentdb-triage-tool Bot added compatibility test Compatibility test related enhancement New feature or request labels May 22, 2026
@documentdb-triage-tool
Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: compatibility test, enhancement
Project fields suggested: Component test-coverage · Priority P2 · Effort L · Status Needs Review
Confidence: 0.92 (mixed)

Reasoning

component from path globs (test-coverage, test-framework); effort from diff stats (926+2 LOC, 6 files); LLM: Adds new integration test coverage for the $first accumulator operator under the compatibility tests path, a functional improvement to test quality.

If a label is wrong, remove it manually and ping @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

@alinaliBQ
Copy link
Copy Markdown
Contributor Author

alinaliBQ commented May 27, 2026

applied #214 (review): Add tests: arity tests, BSON constant tests, expression tests, expression error propagation, empty-group behavior, and order dependence tests

Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Copy link
Copy Markdown
Collaborator

@eerxuan eerxuan left a comment

Choose a reason for hiding this comment

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

Add $sort for each test case.


# Property [BSON Type Preservation]: $first returns the first document's
# value with its BSON type preserved exactly.
FIRST_BSON_TYPE_TESTS: list[AccumulatorTestCase] = [
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Flakiness in FIRST_BSON_TYPE_TESTS and FIRST_SPECIAL_NUMERIC_TESTS

All 17 BSON-type tests have shape docs=[{"v": }, {"v": 999}] and assert the typed value. Same
issue: no $sort, so "first" is whatever the engine returns.

[Required] Either:

  • Add _id to each doc and {"$sort": {"_id": 1}} before $group,

alinaliBQ added 9 commits May 28, 2026 12:20
Update generared files with initial change

Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Add tests: arity tests, BSON constant tests, expression tests, expression error propogation, empty-group behavior, and order dependence tests

Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
"special_float_nan",
docs=[{"v": FLOAT_NAN}, {"v": 999}],
pipeline=[{"$group": {"_id": None, "result": {"$first": "$v"}}}],
expected=[{"_id": None, "result": pytest.approx(math.nan, nan_ok=True)}],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pytest.approx(math.nan, nan_ok=True) is wrong helper here, The framework already has its own NaN-equality handling — _replace_nan at assertions.py:323

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

Labels

compatibility test Compatibility test related enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants