Skip to content

Add $sort stage tests#98

Merged
eerxuan merged 10 commits intodocumentdb:mainfrom
danielfrankcom:pr/sort-tests
Apr 16, 2026
Merged

Add $sort stage tests#98
eerxuan merged 10 commits intodocumentdb:mainfrom
danielfrankcom:pr/sort-tests

Conversation

@danielfrankcom
Copy link
Copy Markdown
Collaborator

@danielfrankcom danielfrankcom commented Apr 14, 2026

This change adds test cases for the $sort aggregation stage, organized into files by property group:

  • test_sort_basic_ordering.py: ascending/descending ordering for all BSON types, equal-value tiebreaking
  • test_sort_numeric.py: cross-type numeric interleaving (int32, int64, double, Decimal128)
  • test_sort_type_comparison.py: BSON type comparison order, within-type ordering rules
  • test_sort_arrays.py: array sort key extraction (min for asc, max for desc), empty/nested arrays
  • test_sort_key_resolution.py: compound sort left-to-right precedence, null/missing field behavior
  • test_sort_field_paths.py: dot notation traversal, array-of-objects extraction, field name acceptance
  • test_sort_direction_values.py: accepted sort order values (int64, double truncation, Decimal128 rounding, $meta)
  • test_sort_order_errors.py: sort order type errors, range errors, error precedence
  • test_sort_spec_errors.py: non-object/empty spec validation, field path validation, compound key limit, duplicate keys
  • test_sort_meta_errors.py: $meta non-meta object, extra keys, and invalid value errors
  • test_stages_position_sort.py: pipeline position behavior, $meta sort with prerequisite stages ($text, $geoNear)

As part of this change I also:

  • Introduced build_raw_bson_doc helper for constructing BSON documents with duplicate keys
  • Added new error codes and test constants used by the sort tests

Please note this change introduces similar machinery to #68, and a rebase will be required once one or the other is merged.

Ref: #34

Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
@danielfrankcom danielfrankcom requested a review from a team as a code owner April 14, 2026 19:39
Comment thread documentdb_tests/framework/error_codes.py
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
…th tests

Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
@danielfrankcom
Copy link
Copy Markdown
Collaborator Author

Due to the new integration test changes, this PR needs #68 to be merged first. It adds the ignore_doc_order parameter to assertResult, which the integration tests require.

Signed-off-by: Daniel Frankcom <frankcom@amazon.com>
@danielfrankcom
Copy link
Copy Markdown
Collaborator Author

The #68 dependency was merged, so this should now be ready for final review.

@danielfrankcom danielfrankcom requested a review from manojnks April 16, 2026 18:38
@eerxuan eerxuan merged commit 6f38689 into documentdb:main Apr 16, 2026
5 checks passed
@danielfrankcom danielfrankcom deleted the pr/sort-tests branch April 20, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants