Aggregation variables
The firstInGroup variable can be used in all nodes with a Script property, whereas the lastInGroup variable can only be used in Agg nodes:
correlation variables
The following correlation variables can only be used in join nodes:
Typical examples of the various join variables can be viewed in the Script property of the X-Ref (Deprecated) node.
Lookup variables
This variable can only be used in a Lookup node:
Other built-in variables
Data360 Analyze Script also contains the following built-in variables to help you configure node output data:
firstInGroup
firstInGroup
is a boolean variable that can be used in any node that has a Script property. In nodes which have a GroupBy property, the value is true for the first instance of each unique value within each field specified in the GroupBy property. In other nodes, the firstInGroup
variable has the same functionality as
the firstExec variable. Commonly used to reset counters and initialize variables on each new value.
Using firstInGroup with a Transform (Deprecated) node
You have the following input data:
type:string |
---|
Type1 |
Type1 |
Type2 |
Type3 |
Type3 |
In the Script property, enter the following:
isFirstInGroup = firstInGroupemit *, isFirstInGroup as "FirstInGroup"
The output would be:
type:string | FirstInGroup:boolean |
---|---|
Type1 | true |
Type1 | false |
Type2 | false |
Type3 | false |
Type3 | false |
Using firstInGroup with an Agg Ex (Deprecated) node
In this example, you have the same input data as in the previous example. In the GroupBy property, enter type
.
In the Script property, enter the following:
isFirstInGroup = firstInGroup
emit *, isFirstInGroup as "FirstInGroup"
The output would be:
type:string | FirstInGroup:boolean |
---|---|
Type1 | true |
Type1 | false |
Type2 | true |
Type3 | true |
Type3 | false |
As shown in this example, the firstInGroup
variable is particularly useful
in Agg nodes and is commonly used to initialize variables and reset
counters when there is a new distinct value in a specified field.
In this final example, you have the following input data to an Agg Ex (Deprecated) node:
name:string | department:string |
---|---|
John | Engineering |
Mary | Engineering |
Bill | Engineering |
Fred | Management |
Bobby | Management |
Clara | Sales |
Jennifer | Sales |
Patty | IT |
In the GroupBy property, enter department.
In the Script property, enter the following:
emit *emit firstInGroup as "IsFirst"
The output would be:
name:string | department:string | IsFirst:boolean |
---|---|---|
John | Engineering | true |
Mary | Engineering | false |
Bill | Engineering | false |
Fred | Management | true |
Bobby | Management | false |
Clara | Sales | true |
Jennifer | Sales | false |
Patty | IT | true |
lastInGroup
lastInGroup
is a boolean variable that can only be used an Agg nodes. The value is true
for the last instance of each unique value within each field specified in the GroupBy property.
By default, lastInGroup
is included in the Script property of the Agg Ex (Deprecated) node to ensure that only one record is output per group after all records have been processed.
lastInGroup
can only be used in Agg nodes. You cannot define a variable called "lastInGroup" on any other nodes. You have the following input data:
type:string |
---|
Type1 |
Type1 |
Type1 |
Type2 |
Type3 |
Type3 |
In an Agg Ex (Deprecated) node, enter type
in the GroupBy property.
In the Script property, enter the following:
emit *isLast = lastInGroupemit isLast
The output would be:
type:string | isLast:boolean |
---|---|
Type1 | false |
Type1 | false |
Type1 | true |
Type2 | true |
Type3 | false |
Type3 | true |
A more common example uses lastInGroup
to control the rows that are output.
In this example, you have the same input data as in the previous example, with
the same GroupBy property.
In this case, enter the following in the Script property:
numberOfRows = countemit type, numberOfRows as "COUNT"
where lastInGroup
The output would be:
type:string | COUNT:int |
---|---|
Type1 | 3 |
Type2 | 1 |
Type3 | 2 |
In this final example, you have the following input data:
name:string | department:string |
---|---|
John | Engineering |
Mary | Engineering |
Bill | Engineering |
Fred | Management |
Bobby | Management |
Clara | Sales |
Jennifer | Sales |
Patty | IT |
In an Agg Ex (Deprecated) node, in the GroupBy property, enter department
.
In the Script property, enter:
emit *emit lastInGroup as "IsLast"
The output would be:
name:string | department:string | IsLast:boolean |
---|---|---|
John | Engineering | false |
Mary | Engineering | false |
Bill | Engineering | true |
Fred | Management | false |
Bobby | Management | true |
Clara | Sales | false |
Jennifer | Sales | true |
Patty | IT | true |
join.type
The join.type
variable can only be used in join nodes. This variable indicates the result of the comparison between the input records, where:
- "l" (left) - indicates that there was no match in the right (bottom) input on the field(s) found in the current left (top) input.
- "i" (inner) - indicates that there was a match on the field(s) for the current left (top) and right (bottom) records.
- "r" (right) - indicates that there was no match in the left (top) input on the field(s) found in the current right (bottom) input.
join.leftOrphan
The join.leftOrphan
variable can only be used in join nodes. join.leftOrphan
is a boolean variable which is true when the join type is "l", indicating that the record could only be located on the left (top) input.
join.rightOrphan
The join.rightOrphan
variable can only be used in join nodes. join.rightOrphan
is a boolean variable which is true when the join type is "r", indicating that the record could only be located on the right (bottom) input.
join.match
The join.match
variable can only be used in join nodes. join.match
is a boolean variable which is true when the join type is "i", indicating that the record was matched across both inputs.
matchIsFound
The matchIsFound
variable can only be used in a Lookup node. matchIsFound
is a boolean variable which is true when a row in the main data (top/left) input was matched based on the corresponding fields in the "Lookup" (bottom/right) input.
execCount
The execCount
variable is a numerical variable (data type int) that can be used to provide a count of the number of records in a data set.
You have the following input data to a Transform (Deprecated) node:
color: string |
---|
Red |
Green |
Blue |
Yellow |
Cyan |
In the Script property, enter the following:
x = execCount
emit x, color
The output would be:
x: long | color: string |
---|---|
1 | Red |
2 | Green |
3 | Blue |
4 | Yellow |
5 | Cyan |
firstExec
The firstExec
variable is a boolean variable which has a value of true for the first value, thereafter, the value is false.
You have the following input data to a Transform (Deprecated) node:
id: int |
---|
1 |
2 |
3 |
4 |
5 |
In the Script property, enter the following:
emit firstExec
The output would be:
firstExec: boolean |
---|
True |
False |
False |
False |
False |
In this example, you want to find the smallest value in a list of positive numbers between zero and 1000. While you would normally use the min
function for this job, you could also do it by inserting the following Data360 Analyze Script into a Transform (Deprecated) node:
if (firstExec) thenminimum = 'number'elseif ('number' < minimum) thenminimum = 'number'emit minimum
In this example, the variable "minimum" is assigned to the first value in the "number" column. The value then only changes if an input record contains a value that is less than the already stored minimum. For example, if the first value in the "number" column is 1, then the "minimum" value that is stored is "1". If a row is then encountered in the "number" column that contains the value "0", "0" becomes the new minumum value.
referencedFields
Analyzes an expression and generates a list of all of the fields that are referenced within it. That list is then used to either emit or exclude those fields from output.
If the expression is in a context where some inputs do not need to be specified, but others do, such as Lookup, then you can provide the default input for fields
that do not list an input. This will prevent an ambiguity error if the field exists on both inputs.
Used in the following format, where outputNumber
is a number that is provided for any fields which do not specify an output (0 means do not provide an output), expression
is an expression that analyzes fields that are referenced and expressions
is any additional expressions that analyze fields that are referenced:
exclude referencedFields(outputNumber, expression {, expressions})
emit referencedFields(outputNumber, expression {, expressions})
Assuming the fields color
and flavor
exist:
emit referencedFields(1, color.trim().concat(2:flavor))
would be equivalent to:
emit 1:color, 2:flavor