Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Feature request: two level sorting

On Jun 18, 12:56pm, Sebastian Gniazdowski wrote:
} Subject: Re: Feature request: two level sorting
} On 16 June 2016 at 09:21, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > Given two arrays AA and AB which must be of equal length:
} > (1) sort AB and apply that new ordering to the elements of AA
} > (2) except that if two elements of AB are the same, use another
} >     sort to order the corresponding elements of AA
} I think yes. Not sure how tricky GROUP BY sorting is, but it sounds
} tricky.

Well, firstly GROUP BY doesn't work the way you seem to think.  It's
not a sort; in SQL a GROUP BY will produce a single row of output that
combines the data from the matching rows, not the original rows
arranged in groups.  The order in which the matching rows accumulate
is unspecified; any ORDER BY is applied to the resulting composites.

What you're really asking for in your original example is sorting by
two different keys, except that you want one key to be a substring
of the input data.  This thing with the parallel arrays amounts to
nothing more than a way to separate out the substring so you can
pretend there are two distinct fields each of which is a key.

The icky bit with zsh is that to sort with any efficiency on multiple
fields you need to be able to manipulate arrays of pointers, but
parameter expansion only gives you arrays of values.

So while I appreciate your "didn't want to mess with data" sentiment,
it might require a lot of reworking of the parameter implementation to
manipulate anything other than the data.  In other words, even if I am
correct about "given two arrays ..." you shouldn't hold your breath
expecting that to get implemented.

} Ultimate solution would be own comparing code

See my other response to Mikael.  tl;dr: Not safe, not something shells
were intended to do, and already done better in other languages.

Messages sorted by: Reverse Date, Date, Thread, Author