Fsdb::F...:dbsort(3)

πŸ“¦
version 3.9 Β· 3 versions
, in epel 9

okay so bestie, this is the man page for dbsort(3) β€” from the User Contributed Perl Documentation set, living in the Fsdb::F...:dbsort corner of the Fsdb universe πŸ’– (yes the module name is literally abbreviated with dots, iykyk). It's a lil Perl filter that sorts your table rows. Let's get into it 🫢

✨ NAME ✨

dbsort β€” sort rows based on the the specified columns 🌸

not me pointing out that the original says "the the" β€” it's iconic, we keep it πŸ’…

🌈 SYNOPSIS 🌈

dbsort [-M MemLimit] [-T TemporaryDirectory] [-nNrR] column [column...]

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically dbsort sorts all your input rows, using whatever columns you point at, either numerically or lexically. Main character sorting behavior πŸ”₯

The genuinely slay part: dbsort consumes a fixed amount of memory no matter how chonky your input is. Like, it literally does not care how big your data gets 😭 (it reverts to temporary files on disk if necessary, and that whole spill-to-disk thing is governed by the -M and -T options).

The sort should be stable, but β€” and this is the tea β€” it has not yet been verified. πŸ™ˆ

For large inputs (the ones that spill to disk), dbsort will do some of the merging in parallel, if possible. The --parallel option can control the degree of parallelism, if desired πŸ‘‘


πŸ’… OPTIONS πŸ’…

The general ones πŸŽ€

  • -M MaxMemBytes β€” specify an approximate limit on memory usage, in bytes. Bigger values = faster sorting, because more operations happen in-memory, provided you have enough memory. It's giving "treat yourself but know your limits" πŸ’€
  • -T TmpDir β€” where to put tmp files. It also uses the environment variable TMPDIR if -T is not specified. Default is /tmp.
  • --parallelism N or -j N β€” allow up to N merges to happen in parallel. Default is the number of CPUs in the machine. Let it cook ⭐

Sort specification options (these can be interspersed with column names 🧚)

  • -r or --descending β€” sort in reverse order (high to low) πŸ“‰
  • -R or --ascending β€” sort in normal order (low to high) πŸ“ˆ
  • -t or --type-inferred-sorting β€” sort fields by type (numeric or leicographic β€” yes that's how it's spelled in the original, we stan), automatically ✨
  • -T or --no-type-inferred-sorting β€” sort fields only as specified, based on -n or -N. (And yes, -T is also the tmp-dir flag up above β€” they're different flags in different option groups, don't come for me, that's just how it is 😭)
  • -n or --numeric β€” sort numerically πŸ”’
  • -N or --lexical β€” sort lexicographically πŸ”€

Also, standard fsdb options, because of course πŸ’œ

  • -d β€” enable debugging output.
  • -i or --input InputSource β€” read from InputSource, typically a file name, or - for standard input, or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects.
  • -o or --output OutputDestination β€” write to OutputDestination, typically a file name, or - for standard output, or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects.
  • --autorun or --noautorun β€” by default, programs process automatically, but Fsdb::Filter objects in Perl do not run until you invoke the run() method. The --(no)autorun option controls that behavior within Perl πŸƒβ€β™€οΈ
  • --header H β€” use H as the full Fsdb header, rather than reading a header from then input. (That "then input" is verbatim, bestie, we love a typo πŸŽ€)
  • --help β€” show help.
  • --man β€” show full manual.

🌸 SAMPLE USAGE 🌸

Input: πŸ“

#fsdb cid cname
10 pascal
11 numanal
12 os

Command: πŸ”₯

cat data.fsdb | dbsort cname

Output: πŸ‘‘

#fsdb      cid     cname
11 numanal
12 os
10 pascal
#  | dbsort cname

⭐ SEE ALSO ⭐

dbmerge(1), dbmapreduce(1), Fsdb(3)


🧚 CLASS FUNCTIONS 🧚

The internals, for when you're feeling brave πŸ’ͺ

new

$filter = new Fsdb::Filter::dbsort(@arguments);

Create a new object, taking command-line arguments.

set_defaults

$filter->set_defaults();

Internal: set up defaults.

parse_options

$filter->parse_options(@ARGV);

Internal: parse command-line arguments.

setup

$filter->setup();

Internal: setup, parse headers.

segment_start

$self->segment_start(\@rows);

Sorting happens internally, to handle large things in pieces if necessary.

call "$self-"segment_start> to init things and to restart after an overflow, "$self-"segment_overflow> to close one segment and start the next, and "$self-"segment_merge_finish> to put them back together again. (Those slightly cursed-looking quoted bits are exactly how they show up in the original β€” not me being chaotic, promise πŸ™ˆ)

Note that we don't invoke the merge code unless the data exceeds some threshold size, so small sorts happen completely in memory. Little sorts stay cozy 🌸

Once we give up on memory, all the merging happens by making passes over the disk files. Disk grind era πŸ’€

segment_next_output

$out = $self->segment_next_output($input_finished)

Internal: return a Fsdb::IO::Writer as $OUT that either points to our output or a temporary file, depending on how things are going.

segment_overflow

$self->segment_overflow(\@rows, $input_finished)

Called to sort @ROWS, writing them to the appropriate place. $INPUT_FINISHED is set if all input has been read.

segment_merge_start

$self->segment_merge_start($fn);

Start merging on file $FN. Fork off a merge thread, if necessary.

segment_merge_finish

$self->segment_merge_finish();

Merge queued files, if any. Just call dbmerge(1) to do all the real work. Outsourcing, slay πŸ’…

run

$filter->run();

Internal: run over each rows.


Copyright (C) 1991-2018 by John Heidemann <johnh@isi.edu>

This program is distributed under terms of the GNU general public license, version 2. See the file COPYING with the distribution for details.


and that's the whole page, bestie β€” no cap, every single flag made it in πŸ’–πŸŽ€βœ¨

cute lil sign-off: this beauty is from perl v5.32.1, dated 2024-08-02 πŸŒˆπŸ¦‹ β€” go sort something iconic, periodt πŸ’œ

πŸ“¦ where this page comes from