Skip to content

Add $avg accumulator tests#190

Merged
eerxuan merged 8 commits into
documentdb:mainfrom
alinaliBQ:avg
May 26, 2026
Merged

Add $avg accumulator tests#190
eerxuan merged 8 commits into
documentdb:mainfrom
alinaliBQ:avg

Conversation

@alinaliBQ
Copy link
Copy Markdown
Contributor

@alinaliBQ alinaliBQ commented May 15, 2026

This change adds tests for the $avg accumulator operator.

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

@alinaliBQ alinaliBQ marked this pull request as ready for review May 15, 2026 22:02
@alinaliBQ alinaliBQ requested a review from a team as a code owner May 15, 2026 22:02
@documentdb-triage-tool documentdb-triage-tool Bot added compatibility test Compatibility test related enhancement New feature or request labels May 15, 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 XL · Status Needs Review
Confidence: 0.92 (mixed)

Reasoning

component from path globs (test-coverage, test-framework); effort from diff stats (2914+0 LOC, 14 files); LLM: Adds new integration test coverage for the $avg accumulator operator under the compatibility tests path, a meaningful but non-blocking functional improvement.

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 alinaliBQ force-pushed the avg branch 2 times, most recently from 3a3a39a to df7d6f5 Compare May 19, 2026 19:28
@alinaliBQ
Copy link
Copy Markdown
Contributor Author

I will address applicable comments for #214 in this PR as well.

@alinaliBQ
Copy link
Copy Markdown
Contributor Author

Removed stage tests and renamed files to test_accumulator_*.py

@alinaliBQ alinaliBQ force-pushed the avg branch 2 times, most recently from 8a875ac to 79910b3 Compare May 21, 2026 22:23
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.

  1. Lost coverage: $group arity tests. The 3 arity tests for $avg in $group ({"$avg": ["$v", "$v"]} →
    expect GROUP_ACCUMULATOR_ARRAY_ARGUMENT_ERROR) were dropped along with the $bucket/$bucketAuto versions.
    The $group ones are genuinely accumulator-contract tests — they're verifying that $avg rejects
    multi-element-array form regardless of stage. Suggest re-adding just the $group cases:
    AccumulatorTestCase("arity_multi_element_group",
    pipeline=[{"$group": {"_id": None, "result": {"$avg": ["$v", "$v"]}}}],
    error_code=GROUP_ACCUMULATOR_ARRAY_ARGUMENT_ERROR,
    msg="$avg should reject multi-element array syntax in $group"),
    AccumulatorTestCase("arity_empty_array_group",
    pipeline=[{"$group": {"_id": None, "result": {"$avg": []}}}],
    error_code=GROUP_ACCUMULATOR_ARRAY_ARGUMENT_ERROR,
    msg="$avg should reject empty array syntax in $group"),
    AccumulatorTestCase("arity_single_element_group",
    pipeline=[{"$group": {"_id": None, "result": {"$avg": ["$v"]}}}],
    error_code=GROUP_ACCUMULATOR_ARRAY_ARGUMENT_ERROR,
    msg="$avg should reject single-element array syntax in $group"),

alinaliBQ added 6 commits May 22, 2026 12:24
used tests from local generate and Daniel F

Signed-off-by: Alina (Xi) Li <[email protected]>

copied AccumulatorTestCase from sum branch

Signed-off-by: Alina (Xi) Li <[email protected]>

convert tests to use

Signed-off-by: Alina (Xi) Li <[email protected]>

Add init.py

Signed-off-by: Alina (Xi) Li <[email protected]>

split into smaller test files

Signed-off-by: Alina (Xi) Li <[email protected]>

remove duplicate tests

Signed-off-by: Alina (Xi) Li <[email protected]>

rename to make tests clearer

Signed-off-by: Alina (Xi) Li <[email protected]>

Avg integration tests

Signed-off-by: Alina (Xi) Li <[email protected]>

style changes

Signed-off-by: Alina (Xi) Li <[email protected]>
Signed-off-by: Alina (Xi) Li <[email protected]>
Signed-off-by: Alina (Xi) Li <[email protected]>
Signed-off-by: Alina (Xi) Li <[email protected]>
Signed-off-by: Alina (Xi) Li <[email protected]>
Signed-off-by: Alina (Xi) Li <[email protected]>
Signed-off-by: Alina (Xi) Li <[email protected]>
@alinaliBQ alinaliBQ requested a review from eerxuan May 25, 2026 23:00
@documentdb documentdb deleted a comment from alinaliBQ May 26, 2026
Signed-off-by: Alina (Xi) Li <[email protected]>
@alinaliBQ
Copy link
Copy Markdown
Contributor Author

@eerxuan Thanks for reviewing, GROUP_ACCUMULATOR_ARRAY_ARGUMENT_ERROR is covered in

GROUP_ACCUMULATOR_ARRAY_ARGUMENT_ERROR_TESTS: list[StageTestCase] = [

I think the $group argument array errors fall under the $group category and not the accumulators.

@eerxuan eerxuan merged commit 088996e into documentdb:main May 26, 2026
12 checks passed
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