Repository navigation
sheet: add sort command with vim-parity flags; fix rowid-shadow bug i… - #677
Merged
Merged
Conversation
…n where/pivot Add `sort`/`sortdesc`/`sortexpr` to the interactive `zsv sheet` viewer, implemented over the existing SQLite path used by `where` and `pivot`: expose the buffer's backing CSV as virtual table `data`, run `select ... order by ...`, and materialize the result into a new buffer. Commands and keys: - `o` / `:sort <column> [asc|desc] [n|f]` ascending column sort - `O` / `:sortdesc` (alias `:sort!`) descending - `:sortexpr <SQL expr> [asc|desc]` order by an arbitrary expression Column sorts group blank/whitespace/missing cells last, sort numeric-looking cells numerically before text, and fold case for ASCII text. Sorting the synthesized Row# column restores original order. `n`/`f` flags give vim-style numeric sorts (n = leading integer, f = float); a flag-shaped token yields to a real column of the same name. Sorts are guaranteed stable via a rowid tiebreak, which also makes a re-sort a true secondary sort on a derived buffer. Fix a pre-existing defect in `where` and pivot drill-down (and the new sort sites): `select ROWID as "Row #", *` binds ROWID to a data column literally named `rowid`, showing that column's values as row numbers. New shared helper zsvsheet_sql_rowid_ref() in sheet-sql.c picks the first unshadowed implicit-rowid spelling (ROWID/_ROWID_/OID); all three commands use it. Tested via the tmux-driven test-sheet harness with discriminating fixtures for each clause (numeric grouping, direction, flag/column ambiguity, stability tiebreak, and the rowid-shadow and triple-shadow cases); clean under ASan+UBSan and leak checking. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Closed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
…n where/pivot
Add
sort/sortdesc/sortexprto the interactivezsv sheetviewer, implemented over the existing SQLite path used bywhereandpivot: expose the buffer's backing CSV as virtual tabledata, runselect ... order by ..., and materialize the result into a new buffer.Commands and keys:
o/:sort <column> [asc|desc] [n|f]ascending column sortO/:sortdesc(alias:sort!) descending:sortexpr <SQL expr> [asc|desc]order by an arbitrary expressionColumn sorts group blank/whitespace/missing cells last, sort numeric-looking cells numerically before text, and fold case for ASCII text. Sorting the synthesized Row# column restores original order.
n/fflags give vim-style numeric sorts (n = leading integer, f = float); a flag-shaped token yields to a real column of the same name. Sorts are guaranteed stable via a rowid tiebreak, which also makes a re-sort a true secondary sort on a derived buffer.Fix a pre-existing defect in
whereand pivot drill-down (and the new sort sites):select ROWID as "Row #", *binds ROWID to a data column literally namedrowid, showing that column's values as row numbers. New shared helper zsvsheet_sql_rowid_ref() in sheet-sql.c picks the first unshadowed implicit-rowid spelling (ROWID/ROWID/OID); all three commands use it.Tested via the tmux-driven test-sheet harness with discriminating fixtures for each clause (numeric grouping, direction, flag/column ambiguity, stability tiebreak, and the rowid-shadow and triple-shadow cases); clean under ASan+UBSan and leak checking.