The relpipe-tr-scheme
is capable to process multiple relations in a single pass.
So we can filter some relations and let others flow unaffected through this pipeline step.
# define some sample relational functions:
r1() { relpipe-in-cli generate seq 1 i integer 1 2 3; } # seq
r2() { relpipe-in-fstab; } # fstab
r3() { find /usr/share/sounds/ -print0 | relpipe-in-filesystem; } # filesystem
# put them together in a single stream function:
sample-data() { r1; r2; r3; }
# let them flow through our Scheme transformation:
sample-data \
| relpipe-tr-scheme \
--relation fstab \
--where '(or (string= $type "btrfs") (string-prefix? "/mnt/" $mount_point) )' \
--relation filesystem \
--where '(and (> $size 8000) (< $size 9000) )' \
| relpipe-out-tabular
Such script will generate something like this:
seq:
╭─────────────╮
│ i (integer) │
├─────────────┤
│ 1 │
│ 2 │
│ 3 │
╰─────────────╯
Record count: 3
fstab:
╭─────────────────┬──────────────────────────────────────┬──────────────────────┬───────────────┬───────────────────────────────────────┬────────────────┬────────────────╮
│ scheme (string) │ device (string) │ mount_point (string) │ type (string) │ options (string) │ dump (integer) │ pass (integer) │
├─────────────────┼──────────────────────────────────────┼──────────────────────┼───────────────┼───────────────────────────────────────┼────────────────┼────────────────┤
│ │ /dev/sde │ /mnt/data │ ext4 │ relatime,user_xattr,errors=remount-ro │ 0 │ 2 │
│ UUID │ a2b5f230-a795-4f6f-a39b-9b57686c86d5 │ /home │ btrfs │ relatime │ 0 │ 2 │
│ │ /dev/mapper/sdf_crypt │ /mnt/private │ xfs │ relatime │ 0 │ 2 │
╰─────────────────┴──────────────────────────────────────┴──────────────────────┴───────────────┴───────────────────────────────────────┴────────────────┴────────────────╯
Record count: 3
filesystem:
╭───────────────────────────────────────────────────────────────────────────┬───────────────┬────────────────┬────────────────┬────────────────╮
│ path (string) │ type (string) │ size (integer) │ owner (string) │ group (string) │
├───────────────────────────────────────────────────────────────────────────┼───────────────┼────────────────┼────────────────┼────────────────┤
│ /usr/share/sounds/Oxygen-Window-All-Desktops-Not.ogg │ f │ 8363 │ root │ root │
│ /usr/share/sounds/KDE-Window-All-Desktops-Not.ogg │ f │ 8363 │ root │ root │
│ /usr/share/sounds/Oxygen-Window-Close.ogg │ f │ 8865 │ root │ root │
│ /usr/share/sounds/KDE-Window-Close.ogg │ f │ 8865 │ root │ root │
│ /usr/share/sounds/KDE-Window-All-Desktops.ogg │ f │ 8712 │ root │ root │
│ /usr/share/sounds/Oxygen-Window-All-Desktops.ogg │ f │ 8712 │ root │ root │
│ /usr/share/sounds/freedesktop/stereo/power-plug.oga │ l │ 8748 │ root │ root │
│ /usr/share/sounds/freedesktop/stereo/bell.oga │ f │ 8495 │ root │ root │
│ /usr/share/sounds/freedesktop/stereo/network-connectivity-established.oga │ l │ 8748 │ root │ root │
│ /usr/share/sounds/freedesktop/stereo/device-removed.oga │ f │ 8500 │ root │ root │
│ /usr/share/sounds/freedesktop/stereo/device-added.oga │ f │ 8748 │ root │ root │
│ /usr/share/sounds/freedesktop/stereo/power-unplug.oga │ l │ 8500 │ root │ root │
│ /usr/share/sounds/freedesktop/stereo/network-connectivity-lost.oga │ l │ 8500 │ root │ root │
╰───────────────────────────────────────────────────────────────────────────┴───────────────┴────────────────┴────────────────┴────────────────╯
Record count: 13
In Scheme, we have filtered the fstab
and filesystem
relations
while the seq
relation was kept intact.
The --relation
option accepts a regular expression.
So it is possible to process more than one relation with it (having all needed attributes in each, of course).
If more --relation
options (e.g. 'f.*'
and fstab
) matches the same relation in the stream, only the first wins and transforms that relation.
If we define some variables in the Scheme context, they will stay there – so we can pass data across relations. Thus we can do even JOIN, if we really want.
Relational pipes, open standard and free software © 2018-2022 GlobalCode