Skip to content

Add $facet tests#669

Open
PatersonProjects wants to merge 8 commits into
documentdb:mainfrom
PatersonProjects:facet_tests
Open

Add $facet tests#669
PatersonProjects wants to merge 8 commits into
documentdb:mainfrom
PatersonProjects:facet_tests

Conversation

@PatersonProjects

Copy link
Copy Markdown
Contributor

This pr adds tests for the $facet stage operator

Ref: Issue #47, #485

Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
This reverts commit 014f2bc.

Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
This reverts commit 51a482a.

Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
@PatersonProjects PatersonProjects requested a review from a team as a code owner July 7, 2026 19:24
Signed-off-by: PatersonProjects <keldonhoff@gmail.com>
@documentdb-triage-tool documentdb-triage-tool Bot added the compatibility test Compatibility test related label Jul 7, 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.85 (mixed)

Reasoning

component from path globs (test-coverage, test-framework); effort from diff stats (1755+0 LOC, 12 files); LLM: Adds new compatibility tests for the $facet aggregation stage operator, expanding test coverage for an existing 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.

@documentdb-triage-tool documentdb-triage-tool Bot added the enhancement New feature or request label Jul 7, 2026
@eerxuan eerxuan requested a review from fanyangv July 13, 2026 18:13


@pytest.mark.aggregate
def test_facet_subpipeline_lookup_basic(collection):

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.

The $lookup test only covers the equi-join form (localField/foreignField). Missing: $lookup with pipeline form inside $facet — this tests nested sub-pipelines ($facet$lookuppipeline → [stages]). Consider adding:

  1. Success tests with pipeline-form $lookup containing multiple stages (e.g., $match, $project, $sort, $group, $unwind, $addFields, etc.)
  2. Error tests with all $facet-forbidden stages ($out, $merge, $collStats, $indexStats, $planCacheStats, $geoNear, $facet) inside the $lookup pipeline to verify they're still rejected when nested inside $facet

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.

Many success/behavior tests (across the whole PR) use a single sub-pipeline. $facet is designed for multiple sub-pipelines on the same input — single-sub-pipeline is a special/minimal case. Consider adding a second sub-pipeline (e.g., "first": [{"$limit": 1}]) to the success cases in test_facet_subpipeline_stages.py, test_stages_position_facet.py, and test_facet_collation.py to make them more realistic.



@pytest.mark.aggregate
@pytest.mark.parametrize("test_case", pytest_params(FACET_SUBPIPELINE_STAGE_TESTS))

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.

Per the container-feature rule (one test per sub-feature), these stages are valid inside $facet but not tested: $redact, $sample, $unionWith, $setWindowFields. Each should have one smoke case confirming it works inside a $facet sub-pipeline.


# Property [Valid Edge Cases]: empty sub-pipelines, many sub-pipelines, and
# unusual-but-valid output field names are accepted.
FACET_ARGUMENT_SUCCESS_TESTS: list[StageTestCase] = [

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.

Missing field name edge cases that should be verified (as either accepted or rejected): spaces ("my field"), hyphens ("my-field"), underscores ("my_field"), numeric-only ("123"), at-sign ("@field"), null byte ("a\x00b"). These should be tested to document the actual behavior — whether they succeed or error.

msg="$facet should yield an empty array when $skip exceeds the document count",
),
StageTestCase(
id="allowDiskUse_true_operates_normally",

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.

Missing the allowDiskUse: false case. Both true and false should be tested to confirm $facet operates normally regardless of the flag value.

# Property [Sub-Pipeline Independence]: a $limit, $match, or $addFields in one
# sub-pipeline does not affect the input seen by another; a runtime error in any
# sub-pipeline fails the whole stage.
FACET_INDEPENDENCE_TESTS: list[StageTestCase] = [

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.

Please add two tests:

  1. $sample before $facet — two sub-pipelines that each return all documents and verify they see exactly the same data
  2. $addFields with $rand before $facet — two sub-pipelines that each return all documents and verify they see exactly the same $rand values

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