Skip to content

feat: implement sort operation for arrays#51

Merged
alvinreal merged 1 commit intomainfrom
fix/issue-22
Feb 21, 2026
Merged

feat: implement sort operation for arrays#51
alvinreal merged 1 commit intomainfrom
fix/issue-22

Conversation

@alvinreal
Copy link
Copy Markdown
Owner

Summary

Implements sort for ordering array elements as specified in #22.

New Operation

sort .field [asc|desc] [, .field2 [asc|desc]]

Sorts array elements by one or more keys with configurable direction.

Examples

sort .name asc
sort .name desc
sort .score desc, .name asc
sort .name

Behavior

  • Default direction is ascending when omitted
  • Null values always sort last regardless of direction
  • Non-array values: no-op (returns value unchanged)
  • Non-existent fields: treated as null (stable order preserved)
  • Multi-key: primary key compared first, ties broken by secondary, etc.
  • Supports integers, floats, and strings

Tests (11 integration tests)

  • sort_name_asc — Alphabetical ascending
  • sort_name_desc — Alphabetical descending
  • sort_multi_key — Multi-key (score desc, name asc)
  • sort_integers — Integer field sorting
  • sort_floats — Float field sorting
  • sort_strings — String field sorting
  • sort_nulls_last_asc — Nulls last in ascending
  • sort_nulls_last_desc — Nulls last in descending
  • sort_nonexistent_field — Non-existent field → stable order
  • sort_non_array_noop — Non-array → no-op
  • sort_default_direction_asc — Default direction is ascending

Fixes #22

- Add sort statement with multi-key support and asc/desc direction
- Default direction is ascending when omitted
- Null values always sort last regardless of direction
- Non-array values are a no-op
- Non-existent fields treated as null (stable order preserved)
- Supports sorting by integers, floats, and strings
- Add 11 integration tests covering all TDD scenarios

Fixes #22
@alvinreal alvinreal merged commit c5b0777 into main Feb 21, 2026
6 checks passed
@github-actions github-actions bot mentioned this pull request Mar 20, 2026
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.

Mapping: sort operation

1 participant