Intermediate Recipe: Using a Function Mechanism

Level: Intermediate
Steps Being Focused on:

  • Function Signature
    This step defines the expected parameters and returns from a chain, similar to a function signature in a programming language.

  • Function Call
    This step emulates a function call by calling another chain which has a defined Function Signature.

Scenario used as an Example:

  • How to retrieve the month from a date string field (e.g., 2022-02-01) in the form of an integer (e.g., 02) by using a Function Mechanism.

Notes:

  • Using a function mechanism helps to:
    – Eliminate explicitly naming of fields in every similar usage of a chain call.
    – Accidentally overwriting of any other fields due to temporary logic names in the called chain.

  1. Navigate to the ETL module & create a new ETL chainset.

  2. In the chainset, add a new chain.
    For example, “Chain A”

  3. Add the step, Function Mechanism with the following inputs as follows:
    *able to specify up to 5 Parameters and Returns each. **![|466x399]

  4. Add the step, String Slice with the following inputs as follows:

  5. Add the step, Change Field Type with the following inputs as follows:

  6. Add the step, Rename Field with the following inputs as follows:

  7. In the same chainset, add another chain.
    For example, “Chain B”

  8. As an example, add the following data using the step, JSON Record

  9. Add 2 Function Call steps as shown below:
    In Fields & Out Fields are as per declared in Step 3


    In Fields & Out Fields are as per declared in Step 3

  10. Run Chain B & you should be able to get results as shown below:

  • firstMonth has extracted the Month from the date string, first
  • secondMonth has extracted the Month from the date string, second
  • unchanged field remains as it is not passed into a function call.

Overview of Chain A

Overview of Chain B