Switch-case statement

<< Click to Display Table of Contents >>

ETL > 12.6 > Implementation Guide > Tutorial and implementation guide > Steps > Mapping 

Switch-case statement

Swich-case statement can be used to define branches for possible values.

The definition has the following syntax:

 

"<target-column-name>": 
{

    "column": "<source-column-name>",

    "switch": [

      {

        "case": "<case-1>",

        "then": "<value-1>"

      },

      {

        "case": "<case-2>",

        "then": "<value-2>"

      },

      {

        "default": "<default-value>"

      }

    ]

  }

}

 

It is not possible to mix the property default with case/then in the same object. The default section is optional, and number of case-then tokens can be any. The default value must be always the last in the collection.

Example

Given the following table SourceTable:

Name

Country

John

US

Helmut

DE

Marcin

PL

Sergey

UA

Sami

FI

Alon

UK

 
And the following JSON step definition:

    {

      "id": 1,

      "name""Example of switch-case",

      "type""map",

      "source""Countries",

      "target""Countries_SwitchCase",

      "columns": {

        "Name""Name",

        "Country": {

          "column""Country",

          "switch": [

            { "case""PL""then""Poland" },

            { "case""DE""then""Germany" },

            { "case""US""then""United States" },

            { "case""FI""then""Finland" },

            { "case""UA""then""Ukraine" },

            { "default""Other country" }

          ] 

        }

      }   

    }
 

The following result table Countries_SwitchCase is expected:

Name

Country

John

United States

Helmut

Germany

Marcin

Poland

Sergey

Ukraine

Sami

Finland

Alon

Other country

 

Fallback values

It is possible to define a custom value returned, if the source column does not exist in the table. For more information about the usage of fallback values, see the Fallback columns chapter.