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

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.

主站蜘蛛池模板: 钦州市| 山西省| 罗田县| 德格县| 玉田县| 枣庄市| 永仁县| 贵南县| 黄梅县| 南丹县| 黔东| 马公市| 辽宁省| 郎溪县| 双峰县| 贵德县| 内丘县| 鄂托克旗| 冀州市| 泰来县| 鄂尔多斯市| 伊宁市| 莆田市| 鹤峰县| 漳浦县| 资溪县| 寿阳县| 隆子县| 涪陵区| 海门市| 双江| 四会市| 准格尔旗| 镇雄县| 通辽市| 炉霍县| 新昌县| 广丰县| 工布江达县| 信阳市| 鄂伦春自治旗|