Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Run a Python script that contains a function on each row of the parent table.

Operator Usage in Easy Mode

  1. Click + on the parent node.
  2. Enter the Run Script operator in the search field and select the operator from the Results to open the operator form.
  3. In the Input Table drop-down, enter or select a table containing the data to run this operator on.
  4. In the Choose Script drop-down, enter or select the name of the script in which function exists.
  5. In the Choose Action drop-down, enter or select an action that will be executed for each row.
  6. In the Explode Fields, choose to explode the output fields by clicking on True or False options.
  7. Click Run to view the result.
  8. Click Save to add the operator to the playbook.
  9. Click Cancel to discard the operator form.

Usage Details

LQL Command

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

operationScript.py

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

LQL Command

runScript(inputTable, 'operationScript.py', 'sum_and_product(val1, val2)', 'true')

output

sum product other_field exit_code
8 15 0

Example 2

command

LQL Command

runScript(inputTable, 'operationScript.py', 'sum_and_product(val1, val2)', 'false')

output

result exit_code
{"sum": 8, "product": 15} 0

Example 3

command

LQL Command

runScript(inputTable, 'operationScript.py', 'double(val1)', 'true')

output

other_field exit_code
6 0

Example 4

command

LQL Command

runScript(inputTable, 'operationScript.py', 'double(val1)', 'false')

output

result exit_code
6 0
  • No labels