Fsdb::F...:dbsort(3)
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 π
-MMaxMemBytes β 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" π-TTmpDir β where to put tmp files. It also uses the environment variableTMPDIRif-Tis not specified. Default is/tmp.--parallelismN or-jN β 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 π§)
-ror--descendingβ sort in reverse order (high to low) π-Ror--ascendingβ sort in normal order (low to high) π-tor--type-inferred-sortingβ sort fields by type (numeric or leicographic β yes that's how it's spelled in the original, we stan), automatically β¨-Tor--no-type-inferred-sortingβ sort fields only as specified, based on-nor-N. (And yes,-Tis 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 π)-nor--numericβ sort numerically π’-Nor--lexicalβ sort lexicographically π€
Also, standard fsdb options, because of course π
-dβ enable debugging output.-ior--inputInputSource β read from InputSource, typically a file name, or-for standard input, or (if in Perl) aIO::Handle,Fsdb::IOorFsdb::BoundedQueueobjects.-oor--outputOutputDestination β write to OutputDestination, typically a file name, or-for standard output, or (if in Perl) aIO::Handle,Fsdb::IOorFsdb::BoundedQueueobjects.--autorunor--noautorunβ by default, programs process automatically, butFsdb::Filterobjects in Perl do not run until you invoke therun()method. The--(no)autorunoption controls that behavior within Perl πββοΈ--headerH β 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.
π AUTHOR and COPYRIGHT π
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
- epel 9: perl-Fsdb 2:3.9-1.el9 Β· GPLv2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms