Skip to content

Add query comparison tests for $eq#696

Open
vic-tsang wants to merge 1 commit into
documentdb:mainfrom
vic-tsang:query/eq/tests
Open

Add query comparison tests for $eq#696
vic-tsang wants to merge 1 commit into
documentdb:mainfrom
vic-tsang:query/eq/tests

Conversation

@vic-tsang

Copy link
Copy Markdown
Collaborator

This PR contains:

  • query comparison tests for $eq

Ref:

Signed-off-by: Victor [C] Tsang <vitsangp@amazon.com>
@vic-tsang
vic-tsang requested a review from a team as a code owner July 20, 2026 23:51
@documentdb-triage-tool documentdb-triage-tool Bot added compatibility test Compatibility test related enhancement New feature or request labels Jul 21, 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); effort from diff stats (1461+0 LOC, 11 files); LLM: Adds new compatibility test cases for the $eq query operator, expanding test coverage in the tests directory.

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.

),
QueryTestCase(
id="decimal128",
filter={"a": {"$eq": Decimal128("1.5")}},

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.

Could be DECIMAL128_ONE_AND_HALF

"""Parametrized test for $eq string-equality subtleties."""
collection.insert_many(test.doc)
result = execute_command(collection, {"find": collection.name, "filter": test.filter})
assertSuccess(result, test.expected, ignore_doc_order=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.

I think the various calls (not just in this file) are not passing through the msg field from the cases which means it won't show up in errors.

)


# (id, docs, value, expected) — the explicit {a: {$eq: value}} and implicit

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.

Style nit: it's quite difficult to follow the case definitions here given the lack of types and clarity on what the parameters of the array mean. Consider using something like this which is closer to the style used elsewhere and more explicit imo:

# Property [Form Equivalence]: the implicit {a: v} form selects the same
# documents as the explicit {a: {$eq: v}} form for any non-regex operand.
# (Regex is the one operand where they diverge; see test_eq_regex.)
EQ_FORM_EQUIVALENCE_TESTS: list[QueryTestCase] = [
    QueryTestCase(
        id="scalar_int",
        filter={"a": {"$eq": 1}},
        doc=[{"_id": 1, "a": 1}, {"_id": 2, "a": 2}],
        msg="$eq int operand should select the same documents in both forms",
    ),
    QueryTestCase(
        id="string",
        filter={"a": {"$eq": "x"}},
        doc=[{"_id": 1, "a": "x"}, {"_id": 2, "a": "y"}],
        msg="$eq string operand should select the same documents in both forms",
    ),
    QueryTestCase(
        id="null_and_missing",
        filter={"a": {"$eq": None}},
        doc=[{"_id": 1, "a": None}, {"_id": 2}, {"_id": 3, "a": 1}],
        msg="$eq null operand should select the same documents in both forms",
    ),
    QueryTestCase(
        id="array",
        filter={"a": {"$eq": [1, 2]}},
        doc=[{"_id": 1, "a": [1, 2]}, {"_id": 2, "a": [1, 2, 3]}],
        msg="$eq array operand should select the same documents in both forms",
    ),
    QueryTestCase(
        id="embedded_document",
        filter={"a": {"$eq": {"b": 1}}},
        doc=[{"_id": 1, "a": {"b": 1}}, {"_id": 2, "a": {"b": 2}}],
        msg="$eq document operand should select the same documents in both forms",
    ),
]


@pytest.mark.parametrize("test", pytest_params(EQ_FORM_EQUIVALENCE_TESTS))
def test_eq_implicit_form_equivalence(collection, test):
    """Test explicit {a: {$eq: v}} and implicit {a: v} forms select the same documents."""
    collection.insert_many(test.doc)
    value = test.filter["a"]["$eq"]
    explicit = execute_command(collection, {"find": collection.name, "filter": test.filter})
    implicit = execute_command(collection, {"find": collection.name, "filter": {"a": value}})
    assertSuccess(
        explicit,
        implicit["cursor"]["firstBatch"],
        ignore_doc_order=True,
        msg=test.msg,
    )

"""Parametrized test for $eq edge cases involving NaN."""
collection.insert_many(test.doc)
result = execute_command(collection, {"find": collection.name, "filter": test.filter})
assertSuccessNaN(result, test.expected, ignore_doc_order=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.

Can we use assertResult here with pytest.approx like we do elsewhere? I don't think this case needs its own dedicated method if the one above is swapped to assertResult. This seems to be using the older style still

]


ALL_TESTS = STRING_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.

Is this needed? Seems redundant

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