relpipe-data/examples-guile-aggregations.xml
author František Kučera <franta-hg@frantovo.cz>
Mon, 21 Feb 2022 00:43:11 +0100
branchv_0
changeset 329 5bc2bb8b7946
parent 316 d7ae02390fac
permissions -rw-r--r--
Release v0.18
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
248
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
<stránka
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
	
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 249
diff changeset
     5
	<nadpis>Aggregating data with Scheme</nadpis>
248
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
	<perex>counting records and computing sum</perex>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
	<m:pořadí-příkladu>01700</m:pořadí-příkladu>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
	<text xmlns="http://www.w3.org/1999/xhtml">
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
		
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
		<p>
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 249
diff changeset
    12
			In <code>relpipe-tr-scheme</code> we can generate new records – not only modify records from the input.
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 249
diff changeset
    13
			There is <code>--has-more-records</code> option which – if evaluated as true – says: „read one more record from the Scheme context and call me again“.
248
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
			We can also suppress all original records by <code>--where '#f'</code>.
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
			And we can also change the structure of the relation (see previous examples).
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
			Thus we can iterate through a relation but completely replace its structure and content.
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
		</p>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
		
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
		<p>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
			What it is good for? We can do aggregations – we can count records, compute sum, maximum, minimum or average value etc.
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
		</p>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
		
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
		<m:pre jazyk="bash" src="examples/guile-file-count-size-sum.sh"/>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
		
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
		<p>Usage example:</p>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		<m:pre jazyk="text"><![CDATA[$ ./guile-file-count-size-sum.sh /usr/share/icons/oxygen/
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
filesystem:
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
 ╭─────────────────┬───────────────╮
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
 │ count (integer) │ sum (integer) │
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
 ├─────────────────┼───────────────┤
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
 │            6260 │      31091700 │
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
 ╰─────────────────┴───────────────╯
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
Record count: 1]]></m:pre>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
		<p>
249
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents: 248
diff changeset
    37
			In SQL, the same result can be achieved by:
248
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
		</p>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		<m:pre jazyk="sql"><![CDATA[SELECT
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	count(*) AS count,
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	sum(size) AS sum
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
FROM filesystem;]]></m:pre>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		<p>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
			This should be possible with <code>relpipe-tr-sql</code> in later versions.
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
			SQL is much more declarative and for many cases a better tool.
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
			In SQL we describe „how the result should look like“ instead of „how the result should be produced step by step“.			
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		</p>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		<p>
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 249
diff changeset
    52
			One day, there might also be a translator that parses SQL code and generates Scheme code,
248
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
			so we could have advantages of both worlds
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
			a) concise and declarative syntax of SQL and 
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
			b) streaming – which means no need for putting all the data in the RAM or on the disk.
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		</p>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
		
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	</text>
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
</stránka>