Skip to content

fix: support mixed ASC/DESC directions in ORDER BY#5

Merged
SebTardif merged 1 commit into
mainfrom
fix/order-by-mixed-directions
Jul 2, 2026
Merged

fix: support mixed ASC/DESC directions in ORDER BY#5
SebTardif merged 1 commit into
mainfrom
fix/order-by-mixed-directions

Conversation

@SebTardif

Copy link
Copy Markdown
Owner

Summary

Fixes #3. ORDER BY with mixed ASC/DESC directions (e.g. ORDER BY name ASC, age DESC) now correctly applies each column's direction independently.

Root Cause

_execute_order_by used a single reverse flag for the entire sorted() call, determined by the first ORDER BY column's direction. All columns were sorted in the same direction.

Fix

Replaced the single-flag approach with a per-column comparator using functools.cmp_to_key. Each ORDER BY column now respects its own ASC/DESC direction. NULL handling is preserved (NULLs sort last regardless of direction).

Test

Added test_order_by_mixed_directions that sorts by active DESC, age ASC and verifies both the group ordering and within-group ordering are correct.

Verification

  • 96 tests pass
  • ruff lint and format clean

Replace single reverse flag with per-column comparator using
functools.cmp_to_key. Each ORDER BY column now respects its own
direction independently.

Closes #3
@SebTardif SebTardif merged commit 4d236c7 into main Jul 2, 2026
8 checks passed
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.

fix: ORDER BY with mixed ASC/DESC directions applies only first column's direction

1 participant