LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
177 stars 31 forks source link

Add exporter option to sort exported items #160

Open nichtich opened 9 years ago

nichtich commented 9 years ago

To sort items by a given field, e.g. sort by field creator.name or to sort reverse by numeric field size:

catmandu convert JSON to JSON --sort creator.name
catmandu convert JSON to JSON --rnsort size

I'd prefer four options sort, nsort, rsort, nrsort instead of sort, numerical and reverse but names can be discussed. Sorting would always imply buffering all items before export.

phochste commented 9 years ago

Can in this case the sort in the to_array() feature be deleted? It would be a much cleaner to do something like:

 Catmandu->importer(...)->select(...)->sort(...)->to_array;

then

Catmandu->importer(...)->select(...)->to_array(sort => ....);
nichtich commented 9 years ago

yes both features should be discussed together.

nichtich commented 9 years ago

PR #161 implements $iterator->sort(...) without extended sorting options. I am not sure how to best express these options in the method and in the command line client. Possible options:

In the CLI I'd prefer short names, such as --rsort ..., this could be alias to --reverse 1 --sort ..., right?