equal
deleted
inserted
replaced
1 <stránka |
1 <stránka |
2 xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana" |
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"> |
3 xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"> |
4 |
4 |
5 <nadpis>Processing multiple relations with Guile</nadpis> |
5 <nadpis>Processing multiple relations with Scheme</nadpis> |
6 <perex>filter some relations and others keep unaffected</perex> |
6 <perex>filter some relations and others keep unaffected</perex> |
7 <m:pořadí-příkladu>01800</m:pořadí-příkladu> |
7 <m:pořadí-příkladu>01800</m:pořadí-příkladu> |
8 |
8 |
9 <text xmlns="http://www.w3.org/1999/xhtml"> |
9 <text xmlns="http://www.w3.org/1999/xhtml"> |
10 |
10 |
11 <p> |
11 <p> |
12 The <code>relpipe-tr-guile</code> is capable to process multiple relations in a single pass. |
12 The <code>relpipe-tr-scheme</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. |
13 So we can filter some relations and let others flow unaffected through this pipeline step. |
14 </p> |
14 </p> |
15 |
15 |
16 <m:pre jazyk="bash"><![CDATA[# define some sample relational functions: |
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 |
17 r1() { relpipe-in-cli generate seq 1 i integer 1 2 3; } # seq |
19 r3() { find /usr/share/sounds/ -print0 | relpipe-in-filesystem; } # filesystem |
19 r3() { find /usr/share/sounds/ -print0 | relpipe-in-filesystem; } # filesystem |
20 |
20 |
21 # put them together in a single stream function: |
21 # put them together in a single stream function: |
22 sample-data() { r1; r2; r3; } |
22 sample-data() { r1; r2; r3; } |
23 |
23 |
24 # let them flow through our Guile transformation: |
24 # let them flow through our Scheme transformation: |
25 sample-data \ |
25 sample-data \ |
26 | relpipe-tr-guile \ |
26 | relpipe-tr-scheme \ |
27 --relation fstab \ |
27 --relation fstab \ |
28 --where '(or (string= $type "btrfs") (string-prefix? "/mnt/" $mount_point) )' \ |
28 --where '(or (string= $type "btrfs") (string-prefix? "/mnt/" $mount_point) )' \ |
29 --relation filesystem \ |
29 --relation filesystem \ |
30 --where '(and (> $size 8000) (< $size 9000) )' \ |
30 --where '(and (> $size 8000) (< $size 9000) )' \ |
31 | relpipe-out-tabular]]></m:pre> |
31 | relpipe-out-tabular]]></m:pre> |
72 ╰───────────────────────────────────────────────────────────────────────────┴───────────────┴────────────────┴────────────────┴────────────────╯ |
72 ╰───────────────────────────────────────────────────────────────────────────┴───────────────┴────────────────┴────────────────┴────────────────╯ |
73 Record count: 13]]></m:pre> |
73 Record count: 13]]></m:pre> |
74 |
74 |
75 |
75 |
76 <p> |
76 <p> |
77 In Guile, we have filtered the <code>fstab</code> and <code>filesystem</code> relations |
77 In Scheme, we have filtered the <code>fstab</code> and <code>filesystem</code> relations |
78 while the <code>seq</code> relation was kept intact. |
78 while the <code>seq</code> relation was kept intact. |
79 </p> |
79 </p> |
80 |
80 |
81 <p> |
81 <p> |
82 The <code>--relation</code> option accepts a regular expression. |
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). |
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. |
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> |
85 </p> |
86 |
86 |
87 <p> |
87 <p> |
88 If we define some variables in the Guile context, they will stay there – so we can pass data across relations. |
88 If we define some variables in the Scheme context, they will stay there – so we can pass data across relations. |
89 Thus we can do even JOIN, if we really want. |
89 Thus we can do even JOIN, if we really want. |
90 </p> |
90 </p> |
91 |
91 |
92 |
92 |
93 </text> |
93 </text> |