SpecStruc-Transform.xml 12 KB

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