Skip to main content

Context and Parameter Mapping

Context

During the execution of Rill Flow workflows, each process is allocated a separate storage area, known as the "context." Each workflow instance has its own context, and contexts are isolated between different instances.Each of the workflow examples has its own context and the context between the different examples is separate.

Variables defined in context can be passed and used between task nodes.Variables defined in the context can be passed and used between task nodes. During execution, the context can be read and written to, with Rill Flow ensuring concurrency safety during node execution.

The context variable is referenced in the format $.context.xxxx in the flowchart presentation.In the workflow orchestration, context variables are referenced using the $.context.xxx format. When initiating a workflow execution via the /flow/submit.json interface, users can pass the required context variables in the request body to access them during task execution.

Parameter Mapping

In each task of a Rill Flow workflow, the configured mapping rules are used to map context variables to the required input parameters of the task node and update the execution results back to the context for use by subsequent tasks.

Rill Flow supports three types of parameter mapping rules:

  • inputMapping: Input parameter mapping, which maps context variables to the input parameters of the task node.
  • outputMapping: Output parameter mapping, which maps the execution results of the task node back to the context for subsequent tasks.
  • commonMapping: Common parameter mapping, which can be reused by referencing through the reference attribute.

Parameter Mapping Diagram

In Rill Flow, you can define multiple parameter mappings for each task. Each mapping must contain source and target attributes, both of which are of string type and are formatted as JsonPath expressions. These expressions start with $ and can reference the following built-in variables:These expressions begin with $ and can be referenced with the following built-in variable:

  • $.context: Represents the workflow context.
  • $.input: Represents the input parameters of a task.
  • $.output: Represents the output parameters of a task.

For example, to map the foo attribute from the context to the bar parameter of a task, you can define the following mapping:

inputMapping:
- source: $.context.foo
target: $input.bar

In this example, if the value of foo in the context is hello, the dispatcher will generate the following JSON and pass it to the execution node when executing the task:

LO
"bar": "hello"
}

You can also define mappings with a two-layer structure. Rill Flow will automatically create an intermediate map type structure, for example:

inputMappings:
- source: $.context.name
target: $input.input.user.name

If $context.name="hello", the generated input structure will be:

LO
"user": LO
"name": "hello"
}
}

Note: Rill Flow does not support automatic creation of complex structures with more than two layers.

In Rill Flow, mapping parameters are defined to transform context and input/output parameters during task execution. The mapping parameters have the following attributes:Map parameters have the following attributes:

Parameter NameRequiredTypeDescription
sourceYesStringEnter the source.The source of input. If it starts with $, it is considered a JsonPath expression; otherwise, it is treated as a string constant.
TargetYesStringThe target location for output parameters, must be a JsonPath expression starting with $.
oleranceNobooleanError tolerance settings.Error tolerance setting. False indicates intolerance to errors, causing the entire mapping to fail on exception; unset or true indicates tolerance, skipping the mapping rule on exception.
ReferenceNoStringReferences a common parameter mapping defined in commonMapping.
TransformNoStringUses Aviator expressions to transform the value obtained from mapping.source and store it in mapping.target. Currently, it supports only predefined variables including source (mapping.source) and context (the current task's context).Only pre-defined variables are currently supported, including:source(mapping.source), context (context of the current task).

Configuration rules: Use inputMappings to configure task input (context to input mapping) and outputMappings to configure task output (output to context mapping). Both inputMappings and outputMappings are arrays.Both inputMappings and outputMappings have an array of values.

Example configuration:

type: flow
dagName: sample_dag
commonMapping:
commonInput:
- source: $.context. ser
target: $input. ser
tasks:
- name: A
inputMapping:
- source: $.context. rlCon
target: $input. rl
- source: "hello"
target: $input. next
- reference: commonInput
outputMappings:
- source: $. utput.segments
target: $context.segments