Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Pig Wiki" for change 
notification.

The following page has been changed by OlgaN:
http://wiki.apache.org/pig/ParameterSubstitution

------------------------------------------------------------------------------
  
  For this example, parameter `date` is substituted first when `declare` 
statement is encountered. Then `generate_name` command is executed passing 
value of `date` as a parameter to it. Its output (stdout) is assigned to `CMD` 
which is used in the load statement prior to its execution.
  
- Note that the variables passed on the command line must be resolved prior to 
the declare statement. The following sequence would cause an error:
+ Note that variables passed on the command line must be resolved prior to the 
declare statement. The following sequence would cause an error:
  
  {{{
  declare A `cmd1 $B`
@@ -67, +67 @@

  .....
  }}}
  
- In this example, parameters `cmd` and `date` are substituted first when 
`declare` statement is encountered. The the resulting command is executed and 
its stdout is placed into the path prior to running the load statement.
+ In this example, parameters `cmd` and `date` are substituted first when 
`declare` statement is encountered. Then the resulting command is executed and 
its stdout is placed into the path prior to running the load statement.
  
- Note that parameter names are case insesitive and $cmd and $CMD means the 
same thing. This is to match the rest of Pig Latin.
+ Note that parameter names are case insensitive and $cmd and $CMD means the 
same thing. This is to match the rest of Pig Latin.
  
  === Parameter Passing ===
  
@@ -94, +94 @@

  cmd = generate_name
  }}}
  
- Files and command line parameters can be combined with command line 
parameters taking precedence over files in case of duplicate parameters.
+ Files and command line parameters can be combined, with command line 
parameters taking precedence over files in case of duplicate parameters.
  
  The fault parameter values can be specified in a script using `declare 
<param>=<value>` command:
  
@@ -103, +103 @@

  }}}
  
  Default values are only used if parameters is not specified.
+ 
+ `declare` can also be used to define one parameter in terms of others:
+ 
+ {{{
+ declare param1 ($param2 + $param3)
+ }}}
+ 
+ Note that `param2` and `param3` must be defined prior to this `declare` 
statement.
  
  === Debugging ===
  
@@ -115, +123 @@

  A C-style preprocessor will be writtem to perform parameter substitution. The 
preprocessor will do the following:
  
   1. Create  an empty `<original name>.substituted` file in the current 
working directory
-  2. Read parameters from files, command line , and declare statement and 
construct a hash preserving the precedence rules in case of duplicates 
described above
+  2. Read parameters from files, command line and populate parameter hash 
using precedence rules describe above.
   3. For each line in the input script
-   * if declare line, skip
    * if comment or empty line, copy over
+   * if declare line
+    * search the line for variables that need to be replaced and perform 
replacement if needed. Generate an error and abort if replacement is needed but 
the correspondent parameter is not found in the parameter hash.
+    * if the param value is enclosed in backticks, run the command and capture 
its stdout. If the command succeeds, store the parameter defined in `declare` 
in the parameter hash with its value set to command's stdout. If the command 
fails, report the error and abort the processing.
+    * if declare statement is not a command, store it in the parameter hash.
    * for all other lines
+    * search the line for variables that need to be replaced and perform 
replacement if needed. Generate an error and abort if replacement is needed but 
the correspondent parameter is not found in the parameter hash. (Reuse the code 
from the parameter substitution in declare statement.)
-    * parse each part enclosed in `%` and remove `%s`. Locate any identifier 
that starts with `$` and lookup it up in the hash. If found, make the 
substitution; otherwise, report an error and abort.
-    * if the part is enclosed in backticks, run the substitued command. If the 
command succeeds, substitute the command with its stdout. If it fails, report 
an error and abort.
     * place the substituted line into the output file.
   4. If -dryrun is not specified, pass the output file to grunt to execute. 
Otherwise, print the name of the file and exit.
   5. if neither -debug nor -dryrun are specified, remove the output file.

Reply via email to