- 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.
- 大數(shù)據(jù)技術(shù)與應(yīng)用基礎(chǔ)
- 大數(shù)據(jù)項目管理:從規(guī)劃到實現(xiàn)
- 大學(xué)計算機(jī)基礎(chǔ):基礎(chǔ)理論篇
- Practical Ansible 2
- 輕松學(xué)Java Web開發(fā)
- Visual Basic從初學(xué)到精通
- 80x86/Pentium微型計算機(jī)原理及應(yīng)用
- 自動控制理論(非自動化專業(yè))
- 項目管理成功利器Project 2007全程解析
- 悟透JavaScript
- Microsoft System Center Confi guration Manager
- 一步步寫嵌入式操作系統(tǒng)
- Raspberry Pi Projects for Kids
- Kubernetes on AWS
- PostgreSQL High Performance Cookbook