relpipe-data/examples-guile-projections.xml
branchv_0
changeset 316 d7ae02390fac
parent 246 fde0cd94fde6
equal deleted inserted replaced
315:d4c2968a391f 316:d7ae02390fac
     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>Doing projections with Guile</nadpis>
     5 	<nadpis>Doing projections with Scheme</nadpis>
     6 	<perex>modifying attribute values and adding new attributes or removing them</perex>
     6 	<perex>modifying attribute values and adding new attributes or removing them</perex>
     7 	<m:pořadí-příkladu>01500</m:pořadí-příkladu>
     7 	<m:pořadí-příkladu>01500</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> can not only filter records,
    12 			The <code>relpipe-tr-scheme</code> can not only filter records,
    13 			but can also modify them and even modify the structure of the relation – add or remove attributes.
    13 			but can also modify them and even modify the structure of the relation – add or remove attributes.
    14 			
    14 			
    15 		</p>
    15 		</p>
    16 		
    16 		
    17 		<h2>Sample data</h2>
    17 		<h2>Sample data</h2>
    53 		</p>
    53 		</p>
    54 
    54 
    55 		<h2>Modifying attribute values</h2>
    55 		<h2>Modifying attribute values</h2>
    56 
    56 
    57 		<p>
    57 		<p>
    58 			Then, we can modify such relation using Guile – e.g. we can make the <code>name</code> uppercase and increase <code>id</code> by 1000:
    58 			Then, we can modify such relation using Scheme – e.g. we can make the <code>name</code> uppercase and increase <code>id</code> by 1000:
    59 		</p>
    59 		</p>
    60 		
    60 		
    61 		<m:pre jazyk="bash"><![CDATA[sample-data \
    61 		<m:pre jazyk="bash"><![CDATA[sample-data \
    62 	| relpipe-tr-guile \
    62 	| relpipe-tr-scheme \
    63 		--relation n \
    63 		--relation n \
    64 		--for-each '(set! $name (string-upcase $name) ) (set! $id (+ $id 1000) )' \
    64 		--for-each '(set! $name (string-upcase $name) ) (set! $id (+ $id 1000) )' \
    65 	| relpipe-out-tabular]]></m:pre>
    65 	| relpipe-out-tabular]]></m:pre>
    66 	
    66 	
    67 		<p>So we have:</p>
    67 		<p>So we have:</p>
    83 			The relation on the output might have different structure that the relation on the input.
    83 			The relation on the output might have different structure that the relation on the input.
    84 			We can keep only some of the original attributes:
    84 			We can keep only some of the original attributes:
    85 		</p>
    85 		</p>
    86 	
    86 	
    87 		<m:pre jazyk="bash"><![CDATA[sample-data \
    87 		<m:pre jazyk="bash"><![CDATA[sample-data \
    88 	| relpipe-tr-guile \
    88 	| relpipe-tr-scheme \
    89 		--relation n \
    89 		--relation n \
    90 		--for-each '(set! $name (string-upcase $name) ) (set! $id (+ $id 1000) )' \
    90 		--for-each '(set! $name (string-upcase $name) ) (set! $id (+ $id 1000) )' \
    91 		--output-attribute 'id' integer \
    91 		--output-attribute 'id' integer \
    92 		--output-attribute 'name' string \
    92 		--output-attribute 'name' string \
    93 	| relpipe-out-tabular]]></m:pre>
    93 	| relpipe-out-tabular]]></m:pre>
   110 			If we do not want to completely redefine the structure of the relation,
   110 			If we do not want to completely redefine the structure of the relation,
   111 			we can keep all original attributes and just add definitions of some others:			
   111 			we can keep all original attributes and just add definitions of some others:			
   112 		</p>
   112 		</p>
   113 		
   113 		
   114 		<m:pre jazyk="bash"><![CDATA[sample-data \
   114 		<m:pre jazyk="bash"><![CDATA[sample-data \
   115 	| relpipe-tr-guile \
   115 	| relpipe-tr-scheme \
   116 		--relation n \
   116 		--relation n \
   117 		--for-each '(define $sum (+ $a $b $c) )' \
   117 		--for-each '(define $sum (+ $a $b $c) )' \
   118 		--output-attribute 'sum' integer \
   118 		--output-attribute 'sum' integer \
   119 		--input-attributes-prepend \
   119 		--input-attributes-prepend \
   120 	| relpipe-out-tabular]]></m:pre>
   120 	| relpipe-out-tabular]]></m:pre>
   142 			Each attribute has a data type (integer, string…).
   142 			Each attribute has a data type (integer, string…).
   143 			And we can change the type. Of course we have to modify the data, because we can not put e.g. string value into an integer attribute.
   143 			And we can change the type. Of course we have to modify the data, because we can not put e.g. string value into an integer attribute.
   144 		</p>
   144 		</p>
   145 		
   145 		
   146 		<m:pre jazyk="bash"><![CDATA[sample-data \
   146 		<m:pre jazyk="bash"><![CDATA[sample-data \
   147 	| relpipe-tr-guile \
   147 	| relpipe-tr-scheme \
   148 		--relation n \
   148 		--relation n \
   149 		--for-each '(define $id (string-upcase $name) )' \
   149 		--for-each '(define $id (string-upcase $name) )' \
   150 		--output-attribute 'id' string \
   150 		--output-attribute 'id' string \
   151 		--output-attribute 'a' integer \
   151 		--output-attribute 'a' integer \
   152 		--output-attribute 'b' integer \
   152 		--output-attribute 'b' integer \
   174 		<p>
   174 		<p>
   175 			We can do projection and restriction at the same time, during the same transformation:
   175 			We can do projection and restriction at the same time, during the same transformation:
   176 		</p>
   176 		</p>
   177 		
   177 		
   178 		<m:pre jazyk="bash"><![CDATA[sample-data \
   178 		<m:pre jazyk="bash"><![CDATA[sample-data \
   179 	| relpipe-tr-guile \
   179 	| relpipe-tr-scheme \
   180 		--relation n \
   180 		--relation n \
   181 		--for-each '(set! $name (string-upcase $name) ) (set! $id (+ $id 1000) )' \
   181 		--for-each '(set! $name (string-upcase $name) ) (set! $id (+ $id 1000) )' \
   182 		--output-attribute 'id' integer \
   182 		--output-attribute 'id' integer \
   183 		--output-attribute 'name' string \
   183 		--output-attribute 'name' string \
   184 		--where '(= $c (* $a $b) )' \
   184 		--where '(= $c (* $a $b) )' \