Module chewdata::step::transformer

source ·
Expand description

Read the data from the input queue and transform it.

§Actions

1 - Get a crate::Context from the input queue.
2 - Extract the crate::DataResult from the crate::Context.
3 - Transform the data with a list of crate::updater::Action.
4 - Create a new crate::Context and attach the crate::DataResult to it.
5 - Push the new crate::Context into the output queue.
6 - Go to step 1 until the input queue is not empty.

§Configuration

keyaliasDescriptionDefault ValuePossible Values
type-Required in order to use transformer steptransformertransformer / transform / t
updateruUpdater type used as a template engine for transformationteratera
referentialsrefsList of crate::step::Reader indexed by their name. A referential can be use to map object during the transformationnull{"alias_a": READER,"alias_b": READER, etc...}
namealiasName stepnullAuto generate alphanumeric value
data_typedataType of data used for the transformation. skip other data typeokok / err
concurrency_limit-Limit of steps to run in concurrence.1unsigned number
§Action
keyDescriptionDefault ValuePossible Values
fieldJson pointer that define the field path created into the output object/alphanumeric or json pointer
patternPattern in django template language format used to build the output field. This project use Tera’s methodsnull
typeType of actionmergemerge current result with the output result / replace the output result with the current result / remove the output field

§Examples

[
    ...
    {
        "type": "transformer",
        "updater": {
            "type": "tera"
        },
        "referentials": {
            "ref_a": {
                "connector": {
                    "type": "io"
                }
            }
        },
        "name": "transform_a",
        "connector": {
            "type": "io"
        },
        "document": {
            "type": "json"
        },
        "data_type": "ok",
        "concurrency_limit": 1,
        "actions": [
            { # Force to set 'output' with the data in 'input'.
                "pattern": "{{ input | json_encode() }}"
            },
            {}, # Do the same as before.
            { # Create a new field 'my_new_field' in the output and set the value with the 'pattern' expression.
                "field": "my_new_field",
                "pattern": "{{ input.number * output.number * ref_a.number * steps.my_previous_step.number }}",
                "type": "merge"
            },
            { # Remove the field 'text'.
                "field": "text",
                "type": "remove"
            },
            { # Replace the 'array' field value.
                "field": "array",
                "pattern": "[\"a\",\"b\"]",
                "type": "replace"
            }
        ]
    }
    ...
]

Structs§