runScript
Run a function of an python script for each row of the input table.
Run a Python script that contains a function on each row of the parent table.
Operator Usage in Easy Mode
- Click + on the parent node.
- Enter the Run Script operator in the search field and select the operator from the Results to open the operator form.
- In the Input Table drop-down, enter or select a table containing the data to run this operator on.
- In the Choose Script drop-down, enter or select the name of the script in which function exists.
- In the Choose Action drop-down, enter or select an action that will be executed for each row.
- In the Explode Fields, choose to explode the output fields by clicking on True or False options.
- Click Run to view the result.
- Click Save to add the operator to the playbook.
- Click Cancel to discard the operator form.
Usage Details
runScript(inputTable, scriptName, entryFunction, explodeFields)
Input:
inputTable
: Table containing the data to run this operator on.
scriptName
: Name of the Python script that contains the function.
entryFunction
: The function to be executed for each row. Use parent column names as function arguments.
explodeFields
: Whether to explode the output fields (true) or not (false).
output:
entryFunction
runs on each row of the parent table.
if explodeFields
is false, the results of entryFunction
appear in a result
column.
if explodeFields
is true, entryFunction
returns a dictionary. The keys of dictionary become columns of the output table.
if explodeFields
is true and entryFunction
returns something other than the dictionary, the result is shown in the other_field
column.
Examples
script
from lhub_integ import action
# Functions annotated with @action can be called in runScript automation
# Try using the actions defined below by mapping columns to the parameters and hit Run
@action
def sum_and_product(column1, column2):
# Return a dictionary to create multiple columns in the output table with explode set true
# If explode is set to false, you will get the dictionary as json in `result` column
return { "sum" : column1 + column2, "product" : column1 * column2 };
@action
def double(column1):
# Return a non-dictionary type to get the value in an `other_field` column
return column1 * 2;
input
val1 | val2 |
---|---|
3 | 5 |
Example 1
command
runScript(inputTable, 'operationScript.py', 'sum_and_product(val1, val2)', 'true')
output
sum | product | other_field | exit_code |
---|---|---|---|
8 | 15 | 0 |
Example 2
command
runScript(inputTable, 'operationScript.py', 'sum_and_product(val1, val2)', 'false')
output
result | exit_code |
---|---|
{"sum": 8, "product": 15} | 0 |
Example 3
command
runScript(inputTable, 'operationScript.py', 'double(val1)', 'true')
output
other_field | exit_code |
---|---|
6 | 0 |
Example 4
command
runScript(inputTable, 'operationScript.py', 'double(val1)', 'false')
output
result | exit_code |
---|---|
6 | 0 |
Updated about 1 year ago