Sort with per-key order
tl;dr
The sort operator in Zed currently lacks the ability to specify order on a per-key basis.
Details
At the time this issue is being filed, Zed it at commit b7d3b41.
This limitation was recently highlighted in a conversation with community user @zmajeed.
Consider this UNIX/Linux sort that's inspired by the examples from this Stack Overflow post:
$ cat sort.csv
field1,field2,field3,field4,field5
2,3,a,9,C
2,2,b,20,Fa
2,2,c,19,Gb
2,2,c,19,Ga
2,2,b,22,Ga
1,10,b,22,Ga
$ tail -n +2 sort.csv | sort -t, -k1,1n -k2,2nr
1,10,b,22,Ga
2,3,a,9,C
2,2,b,20,Fa
2,2,b,22,Ga
2,2,c,19,Ga
2,2,c,19,Gb
Notice how the first column is sorted by acending numeric order and then the second column is sorted in descending numeric order when there's "ties" in the first column.
In Zed there's not currently a way to achieve this in a single call to the sort operator: The -r option in Zed is applied to the totality of keys and can't be simultaneously applied to treatment of different keys like is being done above with the -k2,2nr to get the reverse order in the second key.
$ zq -version
Version: v1.11.1-28-gb7d3b41c
$ zq -f csv 'sort field1,field2' sort.csv
field1,field2,field3,field4,field5
1,10,b,22,Ga
2,2,b,20,Fa
2,2,c,19,Gb
2,2,c,19,Ga
2,2,b,22,Ga
2,3,a,9,C
$ zq -f csv 'sort -r field1,field2' sort.csv
field1,field2,field3,field4,field5
2,3,a,9,C
2,2,b,20,Fa
2,2,c,19,Gb
2,2,c,19,Ga
2,2,b,22,Ga
1,10,b,22,Ga