SpecStruc-Transform.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="TRANSFORM_Structure" role="nobrk">
  5. <title>TRANSFORM Structure<indexterm>
  6. <primary>TRANSFORM structure</primary>
  7. </indexterm></title>
  8. <para><emphasis>resulttype funcname </emphasis><emphasis
  9. role="bold">(</emphasis><emphasis> parameterlist </emphasis><emphasis
  10. role="bold">) := TRANSFORM<indexterm>
  11. <primary>TRANSFORM</primary>
  12. </indexterm> [, SKIP<indexterm>
  13. <primary>SKIP</primary>
  14. </indexterm>( </emphasis><emphasis>condition</emphasis><emphasis
  15. role="bold"> )]</emphasis><emphasis role="bold"> </emphasis></para>
  16. <para><emphasis role="bold"> [ </emphasis><emphasis>locals</emphasis>
  17. <emphasis role="bold">]</emphasis></para>
  18. <para><emphasis role="bold"></emphasis><emphasis role="bold">
  19. SELF</emphasis><indexterm>
  20. <primary>SELF</primary>
  21. </indexterm>.<emphasis>outfield</emphasis> :=
  22. <emphasis>transformation</emphasis>;<emphasis role="bold"></emphasis></para>
  23. <para><emphasis role="bold">END;</emphasis><emphasis
  24. role="bold"></emphasis></para>
  25. <para><emphasis role="bold"></emphasis></para>
  26. <para><emphasis role="bold">TRANSFORM( </emphasis><emphasis>resulttype,
  27. assignments </emphasis><emphasis role="bold"> )</emphasis><emphasis
  28. role="bold"></emphasis></para>
  29. <para><emphasis role="bold"></emphasis></para>
  30. <para><emphasis role="bold">TRANSFORM( </emphasis><emphasis>datarow
  31. </emphasis><emphasis role="bold"> )</emphasis></para>
  32. <informaltable colsep="1" frame="all" rowsep="1">
  33. <tgroup cols="2">
  34. <colspec align="left" colwidth="122.40pt" />
  35. <colspec />
  36. <tbody>
  37. <row>
  38. <entry><emphasis>resulttype</emphasis></entry>
  39. <entry>The name of a RECORD structure Attribute that specifies the
  40. output format of the function. You may use TYPEOF here to specify a
  41. dataset. Any implicit relationality of the input dataset is not
  42. inherited.</entry>
  43. </row>
  44. <row>
  45. <entry><emphasis>funcname</emphasis></entry>
  46. <entry>The name of the function the TRANSFORM structure
  47. defines.</entry>
  48. </row>
  49. <row>
  50. <entry><emphasis>parameterlist</emphasis></entry>
  51. <entry>A comma separated list of the value types and labels of the
  52. parameters that will be passed to the TRANSFORM function. These are
  53. usually the dataset records or COUNTER parameters but are not
  54. limited to those.</entry>
  55. </row>
  56. <row>
  57. <entry><emphasis role="bold">SKIP</emphasis></entry>
  58. <entry>Optional. Specifies the <emphasis>condition</emphasis> under
  59. which the TRANSFORM function operation is skipped.</entry>
  60. </row>
  61. <row>
  62. <entry><emphasis>condition</emphasis></entry>
  63. <entry>A logical expression defining under what circumstances the
  64. TRANSFORM operation does not occur. This may use data from the
  65. <emphasis>parameterlist</emphasis> in the same manner as a
  66. <emphasis>transformation</emphasis> expression.</entry>
  67. </row>
  68. <row>
  69. <entry><emphasis>locals</emphasis></entry>
  70. <entry>Optional. Definitions of local Attributes useful within the
  71. TRANSFORM function. These may be defined to receive parameters and
  72. may use any parameters passed to the TRANSFORM.</entry>
  73. </row>
  74. <row>
  75. <entry><emphasis role="bold">SELF</emphasis></entry>
  76. <entry>Specifies the resulting output recordset from the
  77. TRANSFORM.</entry>
  78. </row>
  79. <row>
  80. <entry><emphasis>outfield</emphasis></entry>
  81. <entry>The name of a field in the <emphasis>resulttype</emphasis>
  82. structure.</entry>
  83. </row>
  84. <row>
  85. <entry><emphasis>transformation</emphasis></entry>
  86. <entry>An expression specifying how to produce the value for the
  87. <emphasis>outfield</emphasis>. This may include other TRANSFORM
  88. function operations (nested transforms).</entry>
  89. </row>
  90. <row>
  91. <entry><emphasis>assignments</emphasis></entry>
  92. <entry>A semi-colon delimited list of
  93. SELF.<emphasis>outfield</emphasis>:=
  94. <emphasis>transformation</emphasis> definitions.</entry>
  95. </row>
  96. <row>
  97. <entry><emphasis>datarow</emphasis></entry>
  98. <entry>A single record to transform, typically the keyword
  99. LEFT.</entry>
  100. </row>
  101. </tbody>
  102. </tgroup>
  103. </informaltable>
  104. <para>The <emphasis role="bold">TRANSFORM </emphasis>structure makes
  105. operations that must be performed on entire datasets (such as a JOIN) and
  106. any iterative type of record processing (PROJECT, ITERATE, etc.), possible.
  107. A TRANSFORM defines the specific operations that must occur on a
  108. record-by-record basis. It defines the function that is called each time the
  109. operation that uses the TRANSFORM needs to process record(s). One TRANSFORM
  110. function may be defined in terms of another, and they may be nested.</para>
  111. <para>The TRANSFORM structure specifies exactly how each field in the output
  112. record set is to receive its value. That result value may simply be the
  113. value of a field in an input record set, or it may be the result of some
  114. complex calculation or conditional expression evaluation.</para>
  115. <para>The TRANSFORM structure itself is a generic tool; each operation that
  116. uses a TRANSFORM function defines what its TRANSFORM needs to receive and
  117. what basic functionality it should provide. Therefore, the real key to
  118. understanding TRANSFORM structures is in understanding how it is used by the
  119. calling function -- each function that uses a TRANSFORM documents the type
  120. of TRANSFORM required to accomplish the goal, although the TRANSFORM itself
  121. may also provide extra functionality and receive extra parameters beyond
  122. those required by the operation itself.</para>
  123. <para>The SKIP option specifies the <emphasis>condition</emphasis> that
  124. results in no output from that iteration of the TRANSFORM. However, COUNTER
  125. values are incremented even when SKIP eliminates generating the current
  126. record.</para>
  127. <sect2 id="Transformation_Attribute_Definitions">
  128. <title>Transformation Attribute Definitions</title>
  129. <para>The attribute definitions inside the TRANSFORM structure are used to
  130. convert the data passed in as parameters to the output
  131. <emphasis>resulttype</emphasis> format. Every field in the
  132. <emphasis>resulttype</emphasis> record layout must be fully defined in the
  133. TRANSFORM. You can explicitly define each field, using the
  134. <emphasis>SELF.outfield</emphasis> := <emphasis>transformation;</emphasis>
  135. expression, or you can use one of these shortcuts:</para>
  136. <programlisting>SELF := [ ];</programlisting>
  137. <para>clears all fields in the <emphasis>resulttype</emphasis> output that
  138. have not previously been defined in the transform function, while this
  139. form:</para>
  140. <programlisting>SELF.<emphasis>outfield</emphasis> := []; //the <emphasis>outfield</emphasis> names a child DATASET in
  141. // the <emphasis>resulttype </emphasis>RECORD Structure</programlisting>
  142. <para>clears only the child fields in the <emphasis>outfield</emphasis>,
  143. and this form:</para>
  144. <programlisting>SELF := <emphasis>label</emphasis>; //the <emphasis>label</emphasis> names a RECORD structure<indexterm>
  145. <primary>RECORD structure</primary>
  146. </indexterm> parameter
  147. // in the <emphasis>parameterlist</emphasis></programlisting>
  148. <para>defines the output for each field in the
  149. <emphasis>resulttype</emphasis> output format that has not previously been
  150. defined as coming from the <emphasis>label</emphasis> parameter's matching
  151. named field.</para>
  152. <para>You may also define <emphasis>local</emphasis> attributes inside the
  153. TRANSFORM structure to better organize the code. These
  154. <emphasis>local</emphasis> attributes may receive parameters.</para>
  155. </sect2>
  156. <sect2 id="TRANSFORM_Functions">
  157. <title>TRANSFORM Functions</title>
  158. <para>This form of TRANSFORM must be terminated by the END keyword. The
  159. <emphasis>resulttype</emphasis> must be specified, and the function itself
  160. takes parameters in the <emphasis>parameterlist</emphasis>. These
  161. parameters are typically RECORD structures, but may be any type of
  162. parameter depending upon the type of TRANSFORM function the using function
  163. expects to call. The exact form a TRANSFORM function must take is always
  164. directly associated with the operation that uses it.</para>
  165. <para>Example:</para>
  166. <programlisting>Ages := RECORD
  167. AgedRecs.id;
  168. AgedRecs.id1;
  169. AgedRecs.id2;
  170. END;
  171. SequencedAges := RECORD
  172. Ages;
  173. INTEGER4 Sequence := 0;
  174. END;
  175. SequencedAges AddSequence(AgedRecs L, INTEGER C) :=
  176. TRANSFORM, SKIP(C % 2 = 0) //skip even recs
  177. INTEGER1 rangex(UNSIGNED4 divisor) := (l.id DIV divisor) % 100;
  178. SELF.id1 := rangex(10000);
  179. SELF.id2 := rangex(100);
  180. SELF.Sequence := C;
  181. SELF := L;
  182. END;
  183. SequencedAgedRecs := PROJECT(AgedRecs, AddSequence(LEFT,COUNTER<indexterm>
  184. <primary>COUNTER</primary>
  185. </indexterm>));
  186. //Example of defining a TRANSFORM function in terms of another
  187. namesIdRecord assignId(namesRecord l, UNSIGNED value) := TRANSFORM
  188. SELF.id := value;
  189. SELF := l;
  190. END;
  191. assignId1(namesRecord l) := assignId(l, 1);
  192. //creates an assignId1 TRANSFORM that uses assignId
  193. assignId2(namesRecord l) := assignId(l, 2);
  194. //creates an assignId2 TRANSFORM that uses assignId</programlisting>
  195. </sect2>
  196. <sect2 id="Inline_TRANSFORMs">
  197. <title>Inline TRANSFORMs<indexterm>
  198. <primary>Inline TRANSFORMs</primary>
  199. </indexterm></title>
  200. <para>This form of TRANSFORM is used in-line within the operation that
  201. uses it. The <emphasis>resulttype</emphasis> must be specified along with
  202. all the <emphasis>assignments</emphasis>. This form is mainly for use
  203. where the transform <emphasis>assignments</emphasis> are trivial (such as
  204. SELF := LEFT;).</para>
  205. <para>Example:</para>
  206. <programlisting>namesIdRecord assignId(namesRecord L) := TRANSFORM
  207. SELF := L; //more like-named fields across
  208. SELF := []; //clear all other fields
  209. END;
  210. projected1 := PROJECT(namesTable, assignId(LEFT));
  211. projected2 := PROJECT(namesTable, TRANSFORM(namesIdRecord,
  212. SELF := LEFT;
  213. SELF := []));
  214. //projected1 and projected2 do the same thing</programlisting>
  215. </sect2>
  216. <sect2 id="Shorthand_Inline_TRANSFORMs">
  217. <title>Shorthand Inline TRANSFORMs<indexterm>
  218. <primary>Inline TRANSFORMs</primary>
  219. </indexterm></title>
  220. <para>This form of TRANSFORM is a shorthand version of Inline TRANSFORMs.
  221. In this form,</para>
  222. <programlisting>TRANSFORM(LEFT)</programlisting>
  223. <para>is directly equivalent to</para>
  224. <programlisting>TRANSFORM(RECORDOF(LEFT), SELF := LEFT)</programlisting>
  225. <para>Example:</para>
  226. <programlisting>namesIdRecord assignId(namesRecord L) := TRANSFORM
  227. SELF := L; //move like-named fields across
  228. END;
  229. projected1 := PROJECT(namesTable, assignId(LEFT));
  230. projected2 := PROJECT(namesTable, TRANSFORM(namesIdRecord,
  231. SELF := LEFT));
  232. projected3 := PROJECT(namesTable, TRANSFORM(LEFT));
  233. //projected1, projected2, and projected3 all do the same thing</programlisting>
  234. <para>See Also: <link linkend="RECORD_Structure">RECORD Structure</link>,
  235. <link linkend="RECORDOF">RECORDOF</link>, <link
  236. linkend="TYPEOF">TYPEOF</link>, <link linkend="JOIN">JOIN</link>, <link
  237. linkend="PROJECT">PROJECT</link>, <link linkend="ITERATE">ITERATE</link>,
  238. <link linkend="ROLLUP">ROLLUP</link>, <link
  239. linkend="NORMALIZE">NORMALIZE</link>, <link
  240. linkend="DENORMALIZE">DENORMALIZE</link>, <link
  241. linkend="FETCH">FETCH</link>, <link linkend="PARSE">PARSE</link>, <link
  242. linkend="ROW">ROW</link></para>
  243. </sect2>
  244. </sect1>