官术网_书友最值得收藏!

Time for action – assigning tasks by filtering priorities with the Switch/Case step

Let's use a Switch/Case step to replace the nested Filter rows steps shown in the previous image.

  1. Create a transformation like the following:
  2. You will find the Switch/Case step in the Flow category of steps.
    Tip

    To save time, you can take as starting point the last transformation you created. Configure the new Microsoft Excel Output steps just as you configured the others but changing the names of the output files.

  3. Create a hop, leaving the Switch/Case step towards the first of the Microsoft Excel Output steps. When prompted for the kind of hop to create, select Create a new target case for this step as shown in the following image:
  4. Create a new hop from the Switch/Case step to the second Microsoft Excel Output step, also selecting Create a new target case for this step.
  5. Do the same again, this time linking the Switch/Case to the third Microsoft Excel Output step.
  6. Finally, create a hop from the Switch/Case step to the fourth Microsoft Excel Output step, but this time select The default target step.
  7. You still have to configure the Switch/Case step. Double-click on it. You will see this:
  8. As Field name to switch select or type Priority.
  9. Now adjust the contents of the Case values grid so it looks like the following:
  10. Save the transformation and run it.
  11. Open the generated Excel files to see that the transformation distributed the task among the files based on the given conditions.

What just happened?

In this section, you learned to use the Switch/Case step. This step routes rows of data to one or more target steps based on the value encountered in a given field.

In the Switch/Case step configuration window, you told Kettle where to send the row depending on a condition. The condition to evaluate was the equality of the field set in Field name to switch and the value indicated in the grid. In this case, the field name to switch is Priority, and the values against which it will be compared are the different values for priorities: Severe, Critical, and so on. Depending on the values of the Priority field, the rows will be sent to any of the target steps. For example, the rows where the value of Priority is Medium will be sent towards the target step New Features for Federica Costa.

Note

Note that it is possible to specify the same target step more than once.

The Default target step represents the step where the rows which don't match any of the case values are sent. In this example, the rows with a priority not present in the list will be sent to the step New Features without priority.

Have a go hero – listing languages and countries

Open the transformation you created in the Time for action – Finding out which language people speak section in Chapter 4, Filtering, Searching, and Performing Other Useful Operations with Data. If you run the transformation and check the content of the output file, you'll notice that there are missing languages. Modify the transformation so that it generates two files: one with the rows where there is a language, that is, the rows for which the lookup succeeded, and another file with the list of countries not found in the countries.xlm file.

Pop quiz – deciding between a Number range step and a Switch/Case step

Continuing with the contestant exercise, suppose that the number of interpreters you will hire depends on the number of people that speak each language:

You want to create a file with the languages with a single interpreter, another file with the languages with two interpreters, and a final file with the languages with three interpreters.

Q1. Which of the following would solve your situation when it comes to splitting the languages into three output streams?

  1. Number range step followed by a Switch/Case step
  2. A Switch/Case step
  3. Both
Tip

In order to figure out the answer, create a transformation and count the number of people that speak each language. You will have to use a Sort rows step followed by a Group by step. After that, try to develop each of the proposed solutions and see what happens.

主站蜘蛛池模板: 西盟| 都昌县| 云南省| 微山县| 遵义市| 梁山县| 长岭县| 谷城县| 灯塔市| 青铜峡市| 旺苍县| 松溪县| 定南县| 玛多县| 潮州市| 嘉善县| 尚义县| 荃湾区| 武汉市| 建平县| 封丘县| 特克斯县| 洛阳市| 铁岭县| 视频| 崇义县| 东莞市| 景洪市| 通州市| 康保县| 四川省| 马龙县| 朝阳区| 香河县| 肇州县| 炎陵县| 合阳县| 承德县| 喀喇| 沈丘县| 丹巴县|