Groovy Script


Execute a user supplied Groovy script which has full read/write access to and from the Dex data stream.


OPTION DESCRIPTION
Program Input This contains the Groovy program to be executed.
Load Load an external Groovy script.
Save Save our Groovy script to an external file.
Process By When "Table", the Dex data stream is sent to the script as a single table and executed once. When "Row" the current row in the Dex data stream is sent to the script and the script is executed for each row in the data data steam. When "Column" the script is executed for each column in the datastream, passing the column as col into the script upon each iteration

The example script above overwrite the dex data stream with a table containing X and Y values where X ranges from -20 to 20 and Y = X * X. Basically, it generates a dataset on the fly without having to read in data from an external source. This can be useful for testing visualizations.

INPUT

Input needs vary with the needs of the user code within.

OUTPUT

Output varies depending on configuration and user supplied code.

Options Description

Process By:

Processing by Table

When processing by table, the script is executed once when the the task is executed and the following variables are made available to the executing script:

VARIABLE CONTENTS
dex This variable contains a reference to the Dex datastream and is of type DexData. This variable has full access to all of the information and utility methods within DexData.
header This is a convenience reference for dex.header and contains the list of strings representing the names of the columns in the dex datastream input.
data This is a convenience reference to dex.data and contains the list of rows representing the values of each row of the dex datastream table.

Any changes to the data or header are made to the Dex datastream output from this task.

Example 1 : Creating a Random Dataset
header = [ "x", "y" ]

int len = 20

Random rand = new Random()

(1..len).each {
  data << [ (it/len).toString(),
           (rand.nextDouble()).toString() ] }
Example 2 : Parsing A CSV File
header = data.remove(0)[1].split(",")

data.eachWithIndex
{
  row, ri ->
  data[ri] = row[1].split(",")
}

Processing by Row

When processing by row, the Groovy script is called for each row in the Dex input datastream table.

The data is made available to the script in a field called "row" which is a map keyed by the column names of the header referencing their values within the row.

VARIABLE CONTENTS
row A map containing keyed by the header names referencing the column's value within this row.
Example 1 : Trimming a Column called NAME
row.NAME = row.NAME.trim()

Processing by Column

When processing by Column, the Groovy script is called for each column in the Dex input datstream table.

The column is made available to the script in a field called "col" which contains the current column's value.

VARIABLE CONTENTS
col A scalar value containing the value of the current column.
Example 1 : Trimming All Columns
col = col?.trim()

results matching ""

    No results matching ""