-
Notifications
You must be signed in to change notification settings - Fork 37
Add $tsIncrement compatibility tests #654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RyanGarfinkel
wants to merge
10
commits into
documentdb:main
Choose a base branch
from
RyanGarfinkel:add-tsIncrement-compatibility-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b1f2652
Add $tsIncrement second-pass tests
RyanGarfinkel 7baa339
Add $tsIncrement wiring test to $match with $expr
RyanGarfinkel 3e5f020
Add $tsIncrement tests for $group expressions
RyanGarfinkel 341c464
Merge branch 'main' into add-tsIncrement-compatibility-tests
RyanGarfinkel ec3c1fb
Merge branch 'main' into add-tsIncrement-compatibility-tests
RyanGarfinkel 3cda6e8
Merge branch 'main' into add-tsIncrement-compatibility-tests
RyanGarfinkel 7629eb9
Merge branch 'documentdb:main' into add-tsIncrement-compatibility-tests
RyanGarfinkel 3a52223
Merge branch 'main' into add-tsIncrement-compatibility-tests
RyanGarfinkel 43afcbe
Add aggregate marker to test_match_with_expr module
RyanGarfinkel 2e12c5c
Merge branch 'main' into add-tsIncrement-compatibility-tests
RyanGarfinkel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
177 changes: 177 additions & 0 deletions
177
...s/compatibility/tests/core/operator/expressions/timestamp/tsIncrement/test_tsIncrement.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from datetime import datetime, timezone | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
| from bson import Binary, Code, Decimal128, Int64, MaxKey, MinKey, ObjectId, Regex, Timestamp | ||
|
|
||
| from documentdb_tests.compatibility.tests.core.operator.expressions.utils.utils import ( | ||
| assert_expression_result, | ||
| execute_expression_with_insert, | ||
| ) | ||
| from documentdb_tests.framework.error_codes import TS_INCREMENT_TYPE_ERROR | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
| from documentdb_tests.framework.test_case import BaseTestCase | ||
|
|
||
| pytestmark = pytest.mark.aggregate | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class TsIncrementTest(BaseTestCase): | ||
| doc: dict[str, Any] | None = None | ||
|
|
||
|
|
||
| TESTS: list[TsIncrementTest] = [ | ||
| TsIncrementTest( | ||
| "null_input", | ||
| doc={"ts": None}, | ||
| expected=None, | ||
| msg="null ts field returns null", | ||
| ), | ||
| TsIncrementTest( | ||
| "missing_field", | ||
| doc={}, | ||
| expected=None, | ||
| msg="missing ts field returns null", | ||
| ), | ||
| TsIncrementTest( | ||
| "ordinal_zero", | ||
| doc={"ts": Timestamp(100, 0)}, | ||
| expected=Int64(0), | ||
| msg="ordinal=0 is returned as Int64(0)", | ||
| ), | ||
| TsIncrementTest( | ||
| "ordinal_one", | ||
| doc={"ts": Timestamp(0, 1)}, | ||
| expected=Int64(1), | ||
| msg="ordinal=1 is returned as Int64(1)", | ||
| ), | ||
| TsIncrementTest( | ||
| "ordinal_max_uint32", | ||
| doc={"ts": Timestamp(0, 4294967295)}, | ||
| expected=Int64(4294967295), | ||
| msg="max uint32 ordinal (4294967295) is preserved as Int64", | ||
| ), | ||
| TsIncrementTest( | ||
| "seconds_ignored", | ||
| doc={"ts": Timestamp(4294967295, 42)}, | ||
| expected=Int64(42), | ||
| msg="only the ordinal component is returned; seconds field is ignored", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_double", | ||
| doc={"ts": 3.14}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="double input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_string", | ||
| doc={"ts": "hello"}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="string input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_object", | ||
| doc={"ts": {"a": 1}}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="object input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_array", | ||
| doc={"ts": [1, 2]}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="array input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_bindata", | ||
| doc={"ts": Binary(b"\x00\x01")}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="Binary input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_objectid", | ||
| doc={"ts": ObjectId("000000000000000000000000")}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="ObjectId input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_bool", | ||
| doc={"ts": True}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="bool input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_date", | ||
| doc={"ts": datetime(2024, 1, 1, tzinfo=timezone.utc)}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="date input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_regex", | ||
| doc={"ts": Regex("^abc")}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="Regex input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_code", | ||
| doc={"ts": Code("function() {}")}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="Code (JavaScript) input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_int", | ||
| doc={"ts": 42}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="int32 input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_long", | ||
| doc={"ts": Int64(100)}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="int64 input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_decimal128", | ||
| doc={"ts": Decimal128("1")}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="Decimal128 input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_minkey", | ||
| doc={"ts": MinKey()}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="MinKey input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| TsIncrementTest( | ||
| "type_maxkey", | ||
| doc={"ts": MaxKey()}, | ||
| error_code=TS_INCREMENT_TYPE_ERROR, | ||
| msg="MaxKey input raises TS_INCREMENT_TYPE_ERROR", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test_case", pytest_params(TESTS)) | ||
| def test_tsIncrement(collection, test_case: TsIncrementTest): | ||
| """Test $tsIncrement operator: null propagation, boundary values, type rejection.""" | ||
| result = execute_expression_with_insert(collection, {"$tsIncrement": "$ts"}, test_case.doc) | ||
| assert_expression_result( | ||
| result, | ||
| expected=test_case.expected, | ||
| error_code=test_case.error_code, | ||
| msg=test_case.msg, | ||
| ) | ||
|
|
||
|
|
||
| def test_tsIncrement_nested_field(collection): | ||
| """$tsIncrement resolves a nested field path ($a.b) to extract the ordinal.""" | ||
| result = execute_expression_with_insert( | ||
| collection, | ||
| {"$tsIncrement": "$a.b"}, | ||
| {"a": {"b": Timestamp(100, 7)}}, | ||
| ) | ||
| assert_expression_result( | ||
| result, expected=Int64(7), msg="nested path $a.b resolves Timestamp correctly" | ||
| ) |
66 changes: 66 additions & 0 deletions
66
documentdb_tests/compatibility/tests/core/operator/stages/group/test_group_expr_operators.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """Tests that expression operators work within $group expressions.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| import pytest | ||
| from bson import Int64, Timestamp | ||
|
|
||
| from documentdb_tests.compatibility.tests.core.operator.stages.utils.stage_test_case import ( | ||
| StageTestCase, | ||
| populate_collection, | ||
| ) | ||
| from documentdb_tests.framework.assertions import assertResult | ||
| from documentdb_tests.framework.executor import execute_command | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
|
|
||
| GROUP_EXPRESSION_TESTS: list[StageTestCase] = [ | ||
| StageTestCase( | ||
| id="group_id_tsIncrement", | ||
| docs=[ | ||
| {"_id": 1, "ts": Timestamp(100, 5)}, | ||
| {"_id": 2, "ts": Timestamp(200, 5)}, | ||
| {"_id": 3, "ts": Timestamp(300, 10)}, | ||
| ], | ||
| pipeline=[ | ||
| {"$group": {"_id": {"$tsIncrement": "$ts"}, "count": {"$sum": 1}}}, | ||
| {"$sort": {"_id": 1}}, | ||
| ], | ||
| expected=[{"_id": Int64(5), "count": 2}, {"_id": Int64(10), "count": 1}], | ||
| msg="$tsIncrement should work as a $group _id expression", | ||
| ), | ||
| StageTestCase( | ||
| id="group_accumulator_tsIncrement", | ||
| docs=[ | ||
| {"_id": 1, "ts": Timestamp(100, 3)}, | ||
| {"_id": 2, "ts": Timestamp(200, 7)}, | ||
| ], | ||
| pipeline=[ | ||
| {"$group": {"_id": None, "max_ordinal": {"$max": {"$tsIncrement": "$ts"}}}}, | ||
| ], | ||
| expected=[{"_id": None, "max_ordinal": Int64(7)}], | ||
| msg="$tsIncrement should work inside an accumulator expression in $group", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.aggregate | ||
| @pytest.mark.parametrize("test_case", pytest_params(GROUP_EXPRESSION_TESTS)) | ||
| def test_group_expression_cases(collection: Any, test_case: StageTestCase): | ||
| """Test that expression operators work within $group.""" | ||
| coll = populate_collection(collection, test_case) | ||
| result = execute_command( | ||
| coll, | ||
| { | ||
| "aggregate": coll.name, | ||
| "pipeline": test_case.pipeline, | ||
| "cursor": {}, | ||
| }, | ||
| ) | ||
| assertResult( | ||
| result, | ||
| expected=test_case.expected, | ||
| error_code=test_case.error_code, | ||
| msg=test_case.msg, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.