|
1 <stránka |
|
2 xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana" |
|
3 xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"> |
|
4 |
|
5 <nadpis>Processing multiple relations with Guile</nadpis> |
|
6 <perex>filter some relations and others keep unaffected</perex> |
|
7 <m:pořadí-příkladu>01800</m:pořadí-příkladu> |
|
8 |
|
9 <text xmlns="http://www.w3.org/1999/xhtml"> |
|
10 |
|
11 <p> |
|
12 The <code>relpipe-tr-guile</code> is capable to process multiple relations in a single pass. |
|
13 So we can filter some relations and let others flow unaffected through this pipeline step. |
|
14 </p> |
|
15 |
|
16 <m:pre jazyk="bash"><![CDATA[# define some sample relational functions: |
|
17 r1() { relpipe-in-cli generate seq 1 i integer 1 2 3; } # seq |
|
18 r2() { relpipe-in-fstab; } # fstab |
|
19 r3() { find /usr/share/sounds/ -print0 | relpipe-in-filesystem; } # filesystem |
|
20 |
|
21 # put them together in a single stream function: |
|
22 sample-data() { r1; r2; r3; } |
|
23 |
|
24 # let them flow through our Guile transformation: |
|
25 sample-data \ |
|
26 | relpipe-tr-guile \ |
|
27 --relation fstab \ |
|
28 --where '(or (string= $type "btrfs") (string-prefix? "/mnt/" $mount_point) )' \ |
|
29 --relation filesystem \ |
|
30 --where '(and (> $size 8000) (< $size 9000) )' \ |
|
31 | relpipe-out-tabular]]></m:pre> |
|
32 |
|
33 <p>Such script will generate something like this:</p> |
|
34 |
|
35 <m:pre jazyk="text"><![CDATA[seq: |
|
36 ╭─────────────╮ |
|
37 │ i (integer) │ |
|
38 ├─────────────┤ |
|
39 │ 1 │ |
|
40 │ 2 │ |
|
41 │ 3 │ |
|
42 ╰─────────────╯ |
|
43 Record count: 3 |
|
44 |
|
45 fstab: |
|
46 ╭─────────────────┬──────────────────────────────────────┬──────────────────────┬───────────────┬───────────────────────────────────────┬────────────────┬────────────────╮ |
|
47 │ scheme (string) │ device (string) │ mount_point (string) │ type (string) │ options (string) │ dump (integer) │ pass (integer) │ |
|
48 ├─────────────────┼──────────────────────────────────────┼──────────────────────┼───────────────┼───────────────────────────────────────┼────────────────┼────────────────┤ |
|
49 │ │ /dev/sde │ /mnt/data │ ext4 │ relatime,user_xattr,errors=remount-ro │ 0 │ 2 │ |
|
50 │ UUID │ a2b5f230-a795-4f6f-a39b-9b57686c86d5 │ /home │ btrfs │ relatime │ 0 │ 2 │ |
|
51 │ │ /dev/mapper/sdf_crypt │ /mnt/private │ xfs │ relatime │ 0 │ 2 │ |
|
52 ╰─────────────────┴──────────────────────────────────────┴──────────────────────┴───────────────┴───────────────────────────────────────┴────────────────┴────────────────╯ |
|
53 Record count: 3 |
|
54 |
|
55 filesystem: |
|
56 ╭───────────────────────────────────────────────────────────────────────────┬───────────────┬────────────────┬────────────────┬────────────────╮ |
|
57 │ path (string) │ type (string) │ size (integer) │ owner (string) │ group (string) │ |
|
58 ├───────────────────────────────────────────────────────────────────────────┼───────────────┼────────────────┼────────────────┼────────────────┤ |
|
59 │ /usr/share/sounds/Oxygen-Window-All-Desktops-Not.ogg │ f │ 8363 │ root │ root │ |
|
60 │ /usr/share/sounds/KDE-Window-All-Desktops-Not.ogg │ f │ 8363 │ root │ root │ |
|
61 │ /usr/share/sounds/Oxygen-Window-Close.ogg │ f │ 8865 │ root │ root │ |
|
62 │ /usr/share/sounds/KDE-Window-Close.ogg │ f │ 8865 │ root │ root │ |
|
63 │ /usr/share/sounds/KDE-Window-All-Desktops.ogg │ f │ 8712 │ root │ root │ |
|
64 │ /usr/share/sounds/Oxygen-Window-All-Desktops.ogg │ f │ 8712 │ root │ root │ |
|
65 │ /usr/share/sounds/freedesktop/stereo/power-plug.oga │ l │ 8748 │ root │ root │ |
|
66 │ /usr/share/sounds/freedesktop/stereo/bell.oga │ f │ 8495 │ root │ root │ |
|
67 │ /usr/share/sounds/freedesktop/stereo/network-connectivity-established.oga │ l │ 8748 │ root │ root │ |
|
68 │ /usr/share/sounds/freedesktop/stereo/device-removed.oga │ f │ 8500 │ root │ root │ |
|
69 │ /usr/share/sounds/freedesktop/stereo/device-added.oga │ f │ 8748 │ root │ root │ |
|
70 │ /usr/share/sounds/freedesktop/stereo/power-unplug.oga │ l │ 8500 │ root │ root │ |
|
71 │ /usr/share/sounds/freedesktop/stereo/network-connectivity-lost.oga │ l │ 8500 │ root │ root │ |
|
72 ╰───────────────────────────────────────────────────────────────────────────┴───────────────┴────────────────┴────────────────┴────────────────╯ |
|
73 Record count: 13]]></m:pre> |
|
74 |
|
75 |
|
76 <p> |
|
77 In Guile, we have filtered the <code>fstab</code> and <code>filesystem</code> relations |
|
78 while the <code>seq</code> relation was kept intact. |
|
79 </p> |
|
80 |
|
81 <p> |
|
82 The <code>--relation</code> option accepts a regular expression. |
|
83 So it is possible to process more than one relation with it (having all needed attributes in each, of course). |
|
84 If more <code>--relation</code> options (e.g. <code>'f.*'</code> and <code>fstab</code>) matches the same relation in the stream, only the first wins and transforms that relation. |
|
85 </p> |
|
86 |
|
87 <p> |
|
88 If we define some variables in the Guile context, they will stay there – so we can pass data across relations. |
|
89 Thus we can do even JOIN, if we really want. |
|
90 </p> |
|
91 |
|
92 |
|
93 </text> |
|
94 |
|
95 </stránka> |