- Pentaho Data Integration Beginner's Guide(Second Edition)
- María Carina Roldán
- 709字
- 2021-07-23 15:47:02
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.
- Create a transformation like the following:
- 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.
- 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:
- 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.
- Do the same again, this time linking the Switch/Case to the third Microsoft Excel Output step.
- Finally, create a hop from the Switch/Case step to the fourth Microsoft Excel Output step, but this time select The default target step.
- You still have to configure the Switch/Case step. Double-click on it. You will see this:
- As Field name to switch select or type
Priority
. - Now adjust the contents of the Case values grid so it looks like the following:
- Save the transformation and run it.
- 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?
- Number range step followed by a Switch/Case step
- A Switch/Case step
- 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.
- 虛擬儀器設計測控應用典型實例
- 工業機器人虛擬仿真實例教程:KUKA.Sim Pro(全彩版)
- Internet接入·網絡安全
- 我的J2EE成功之路
- AutoCAD快速入門與工程制圖
- Mastercam 2017數控加工自動編程經典實例(第4版)
- Getting Started with MariaDB
- 自動化控制工程設計
- Blender 3D Printing by Example
- 網絡服務搭建、配置與管理大全(Linux版)
- Mastering Exploratory Analysis with pandas
- Xilinx FPGA高級設計及應用
- 計算機硬件技術基礎(第2版)
- Oracle 11g Anti-hacker's Cookbook
- 分布式Java應用