Skip to content

Add $last accumulator tests#231

Open
alinaliBQ wants to merge 16 commits into
documentdb:mainfrom
alinaliBQ:last
Open

Add $last accumulator tests#231
alinaliBQ wants to merge 16 commits into
documentdb:mainfrom
alinaliBQ:last

Conversation

@alinaliBQ
Copy link
Copy Markdown
Contributor

This change adds tests for the $last accumulator operator.

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

@alinaliBQ alinaliBQ marked this pull request as ready for review May 22, 2026 23:02
@alinaliBQ alinaliBQ requested a review from a team as a code owner May 22, 2026 23:02
@documentdb-triage-tool documentdb-triage-tool Bot added compatibility test Compatibility test related enhancement New feature or request labels May 23, 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); effort from diff stats (1520+4 LOC, 7 files); LLM: Adds new integration test coverage for the $last accumulator operator under the compatibility tests path, expanding functional test surface for an important aggregation feature.

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 added 13 commits May 26, 2026 14:29
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>
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>
@alinaliBQ
Copy link
Copy Markdown
Contributor Author

applied #214 (review): Add tests: arity error tests, BSON constant tests, expression tests, and empty-group behavior tests. Removed Code tests.

Add tests: arity error tests, BSON constant tests, expression tests, empty-group behavior, and order dependence tests. Removed  tests.

Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
"expr_error_divide_by_zero",
docs=[{"v": 1}],
pipeline=[
{"$group": {"_id": None, "result": {"$last": {"$divide": ["$v", 0]}}}},
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.

Can you add a field path trigger error?
{"$divide": [1, "$v"]} with docs=[{"v": 0}].

and test if docs before last can trigger it. docs=[{"v": 1}, {"v": 0}]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added the suggested tests

{"$group": {"_id": None, "result": {"$last": "$v"}}},
{"$project": {"_id": 0, "result": 1}},
],
expected=[{"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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed to use assertSuccessNaN

alinaliBQ added 2 commits May 28, 2026 15:00
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Signed-off-by: Alina (Xi) Li <Alina.Li@improving.com>
Copy link
Copy Markdown
Contributor Author

@alinaliBQ alinaliBQ left a comment

Choose a reason for hiding this comment

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

addressed comments

{"$group": {"_id": None, "result": {"$last": "$v"}}},
{"$project": {"_id": 0, "result": 1}},
],
expected=[{"result": pytest.approx(math.nan, nan_ok=True)}],
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed to use assertSuccessNaN

"expr_error_divide_by_zero",
docs=[{"v": 1}],
pipeline=[
{"$group": {"_id": None, "result": {"$last": {"$divide": ["$v", 0]}}}},
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added the suggested tests

@alinaliBQ alinaliBQ requested a review from eerxuan May 28, 2026 22:25
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