kettle子转换即映射
kettle子转换即映射 子转换是非常好的特性,可以实现整个转换重用;所以如果你需要拷贝、粘贴一些相同的步骤到多个其他转换中,就可以考虑使用子转换(即映射),可以使你的ETL程序更简洁。 子转换通常从父转换中接收行输入数据,针对输入数据进行处理,再传
kettle子转换即映射
子转换是非常好的特性,可以实现整个转换重用;所以如果你需要拷贝、粘贴一些相同的步骤到多个其他转换中,就可以考虑使用子转换(即映射),可以使你的ETL程序更简洁。
子转换通常从父转换中接收行输入数据,针对输入数据进行处理,再传回给父转换。所以子转换需要有一个输入步骤和用于运行时连接到父转换的输出步骤。这些接口步骤中定义输入、输出行数据的字段结构。子转换为了实现可重用性,所以当父转换调用子转换,父转换的行字段被映射到子转换的字段作为输入;同样映射发生在处理完,返回给父转换。所以子转换也称之为映射。
下面通过示例学习子转换,把计算的内容重构,放入到一个子转换中。示例代码在这里下载。示例中的奇偶校验代码可能需要参考另一篇文章。
示例转换
本示例是针对数字做计算,接收一个输入值并计算奇偶校验位(二进制中1的位数),并计算所有位数数字之和(十进制表示中数字之和),最后输出到excel中。
示例比较简单,假设该计算需要在项目的其他几个转换中使用,让我们重构上面示例,让其可以在其它转换中调用。
子转换存储在一个单独的文件中。“Mapping input specification”步骤作为输入,计算步骤在中间,”Mappingoutput specification”步骤作为输出,这些和映射相关的步骤在Mapping分类中。下图显示了输入步骤的配置。需要父转换转入一个整型字段名称为value到当前子转换,这些字段可能在后面的步骤中使用。复选框表示其他字段也将传入,他们流经子转换不受影响;这非常有用,如果父转换有多个字段,而子转换只需要其中一部分字段,就需要使用此选项确保其他字段不受影响。
计算步骤保存不变,输出另外两个字段,分别为奇偶校验位和位数之和。输出步骤无需配置,作用为提供从前面步骤输出字段给父转换。
到此子转换设计已经完成,现在需要给父转换调用,选择“Mapping”步骤(子转换)来实现。映射步骤需要确定调用那个子转换及是否需要传入任何命名参数,以及其他一些转换的公共属性;子转换很容易指定,通过文件或库路径指定。“generate random integer”步骤数据流传入子转换,子转换处理后的数据流输出到“Excel Output”步骤。把子转换连接在generate random integer”步骤和“Excel Output”步骤之间。然后在子转换步骤配置中,增加输入选项卡和输出选项卡,并且都选中两者“Is this the main data path?”选项,这就告诉kettle根据连接的原步骤和目标步骤来演绎。另外输入选项卡需要指定输入行字段和子转换的字段之间的映射关系。示例中的唯一输入字段已经是value,所以配置很容易。

关于子转换的重构已经完成,主转换调用子转换并存储结果到excel中,可以下载示例进行验证。
保留字段名称
上面的示例字段映射比较简单。实际场景中输入字段不一定和子转换中定义的名称一致。这时你可以选择让子转换做起工作并返回子转换中的字段名称,或者选择把子转换中的字段重命名成原来的输入的名称。通过“Ask these values to be renamed back on output?”选项实现,假设你映射输入字段”foo”到子转换的名称“bar”,如果你不选中该选项,表示从子转换中输出字段名称为bar;反之选中该选项,输出字段名称还是原来的foo。这个特性让子转换具有解耦性相对父转换。
上面示例子转换仅有一个输入、输出,然而子转换可以有多个输入、输出。为了演示,我们分离计算步骤成两条独立的路径,分别为计算奇偶校验位和技术位数和。
现在子转换有两个输入、输出,从父转换的整数值需要传入到两个输入并且输出到不同的excel文件中。这样保存奇偶校验位在一个文件中,位数之和在另一个文件中。父转换也需要重构并改变。
如果你下载了示例,你将注意映射步骤有两个输入和输出。“Is this the main data path?”选项不再选中,期望kettle根据连接从输入到输出已不现实。原步骤和目标步骤都是手工定义的;其实映射步骤和输入、输出之间的连接是象征性的,完全可以删除连接却不影响运行(不用担心,你完全可以试试)。示例中保留连接,这样看起来比较习惯。另外需要指出的是,“Generate random integer”步骤有两个后续步骤(子转换的两个输入步骤),因此需要复制记录到两个后续步骤,而不是分发。
结论
kettle映射特性让转换有了可重用性,让ETL程序具有简洁性。其输入、输出步骤及参数配置非常灵活,几乎可以让任何复杂的转换重构成可重用的子转换。如果转换比较大,也可以重构成连续的子转换组合实现。子转换让转换数据流案结构化,更容易理解。
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When using word in WPS, you often need to insert pictures, tables, etc., but if the inserted table is not centered, it will affect the beauty of the entire document. So how to set the centering of the WPS table? Today I will teach you how to make adjustments. The specific steps are as follows. Come and take a look! 1. The table in the picture is not in the middle of the page, which is not very beautiful. I want it to be centered. 2. First, right-click the mouse in the table (as shown in the picture). 3. Then click [Select All Tables] in the right-click menu (as shown by the red arrow in the figure). 4. After clicking, the table will be fully selected (as shown in the figure below). 5. At this time, click to open the [Start] tab of wps text (as shown by the red arrow in the figure). 6 o'clock

Are you also using Adobe Acrobat Pro 9 software in your office? But do you know how to insert pictures in Adobe Acrobat Pro 9? Below, the editor will bring you the method of inserting pictures in Adobe Acrobat Pro 9. If you are interested, take a look below. Open the Sample.pdf document in Adobe Acrobat Pro9, click "Tools" - "Content" - select "Edit Object" on the right side of the document, and the mouse cursor changes to a solid arrow + a small box in the lower right corner. Right-click in an empty space of the document and select Insert Image. A dialog box will pop up, then select the ElenaGilbert.JPEG image file in the dialog box (please confirm

Do you know how to split cells in Microsoft Excel? Below, the editor will bring you the method of splitting cells in Microsoft Excel. I hope it will be helpful to you. Let’s learn with the editor! 1. First open the merged cells Excel table, as shown below. 2. Select the merged cells and click the "Merge Center" button with the downward arrow at the top, as shown in the figure below. 3. Then select "Unmerge Cells", as shown in the figure below. 4. Now you can find that the cells have been split, as shown in the figure below. The above is the entire content of how to split cells in Microsoft Excel brought to you by the editor. I hope it can be helpful to you.

Practical tips for converting full-width English letters into half-width forms. In modern life, we often come into contact with English letters, and we often need to input English letters when using computers, mobile phones and other devices. However, sometimes we encounter full-width English letters, and we need to use the half-width form. So, how to convert full-width English letters to half-width form? Here are some practical tips for you. First of all, full-width English letters and numbers refer to characters that occupy a full-width position in the input method, while half-width English letters and numbers occupy a full-width position.

This article will introduce in detail how to convert months in PHP to English months, and give specific code examples. In PHP development, sometimes we need to convert digital months to English months, which is very practical in some date processing or data display scenarios. The implementation principles, specific code examples and precautions will be explained in detail below. 1. Implementation principle In PHP, you can convert digital months into English months by using the DateTime class and format method. Date

QQ Music allows everyone to enjoy watching movies and relieve boredom. You can use this software every day to easily satisfy your needs. A large number of high-quality songs are available for everyone to listen to. You can also download and save them. The next time you listen to them, you don’t need an Internet connection. The songs downloaded here are not in MP3 format and cannot be used on other platforms. After the membership songs expire, there is no way to listen to them again. Therefore, many friends want to convert the songs into MP3 format. Here, the editor explains You provide methods so that everyone can use them! 1. Open QQ Music on your computer, click the [Main Menu] button in the upper right corner, click [Audio Transcoding], select the [Add Song] option, and add the songs that need to be converted; 2. After adding the songs, click to select Convert to [mp3]

PHP Tutorial: How to Convert Int Type to String In PHP, converting integer data to string is a common operation. This tutorial will introduce how to use PHP's built-in functions to convert the int type to a string, while providing specific code examples. Use cast: In PHP, you can use cast to convert integer data into a string. This method is very simple. You only need to add (string) before the integer data to convert it into a string. Below is a simple sample code

How to convert full-width English letters into half-width letters In daily life and work, sometimes we encounter situations where we need to convert full-width English letters into half-width letters, such as when entering computer passwords, editing documents, or designing layouts. Full-width English letters and numbers refer to characters with the same width as Chinese characters, while half-width English letters refer to characters with a narrower width. In actual operation, we need to master some simple methods to convert full-width English letters into half-width letters so that we can process text and numbers more conveniently. 1. Full-width English letters and half-width English letters
