4 ms·
Assuming you want to do this on a single machine with finite memory, a feasible approach would be: 1. Split into multiple shard using e.g. `split`, where each
by mattewong 5y ago
Assuming you want to do this on a single machine with finite memory, a feasible approach would be:
1. Split into multiple shard using e.g. `split`, where each piece is small enough to fit comfortably into memory
2. Sort each shard. You could use something like `zsv` (sql sub-command) (https://github.com/liquidaty/zsv https://github.com/liquidaty/zsv) or `xsv` (sort subcommand) (https://github.com/BurntSushi/xsv https://github.com/BurntSushi/xsv) for this
3. Use mergesort to sort all shards, at the same time, into a single output table, and in the process, de-dupe and/or merge (if you had too many shards for your operating system to allow so many files to be open at once, you might need to do an intermediate merge to consolidate shards)
For #3, I don't know of a tool to do this-- probably one exists for simple de-duping, but it may be harder if you need support for merge logic. If a tool for this does not exist, I would be imagine `zsv` could quite be easily extended to handle it.