EBOOK PENTAHO DATA INTEGRATION 4 COOKBOOK
Editorial Reviews. About the Author. Adrián Sergio Pulvirenti. Adrián was born in Buenos Aires, Pentaho Data Integration 4 Cookbook Kindle Edition. by Adrian . Pentaho Data Integration 4 Cookbook. María Carina Roldán, Adrián Sergio Pulvirenti. June pages. 10 hours 33 minutes. Over Compre o livro Pentaho Data Integration 4 Cookbook na resourceone.info: Pentaho Data Integration 4 Cookbook (English Edition) e mais milhares de eBooks.
|Language:||English, Spanish, Japanese|
|ePub File Size:||26.67 MB|
|PDF File Size:||13.13 MB|
|Distribution:||Free* [*Regsitration Required]|
Pentaho Data Integration 4 CookbookOver 70 recipes to solve ETL problems using Pentaho KettleAdrián Sergio Pulviren. Pentaho Data Integration 4 Cookbook shows you how to take advantage of all the aspects of Kettle through a Support files, eBooks, discount offers and more. Contribute to happyapple/gavin-repo development by creating an account on GitHub.
In the SQL frame type the following statement: Check the option Replace variables in script? Use an Output step like for example a Text file output step, to send the results to a file, save the transformation, and run it. Open the generated file and you will see the books ordered by title.
Now try again. Press F9 to run the transformation one more time. Press the Launch button. Open the generated file. This time you will see the titles ordered by genre. When the transformation is initialized, PDI replaces the variables by their values provided that the Replace variables in script? You could even hold the full statement in a variable.
Note however that you need to be cautious when implementing this. A wrong assumption about the metadata generated by those predefined statements can make your transformation crash. You can also use the same variable more than once in the same statement. This is an advantage of using variables as an alternative to question marks when you need to execute parameterized SELECT statements.
See also f Getting data from a database by providing parameters. This recipe shows you an alternative way to parameterize a query. Inserting or updating rows in a table Two of the most common operations on databases besides retrieving data are inserting and updating rows in a table. PDI has several steps that allow you to perform these operations.
Before inserting or updating rows in a table by using this step, it is critical that you know which field or fields in the table uniquely identify a row in the table. If you don't have a way to uniquely identify the records, you should consider other steps, as explained in the There's more Assume this situation: You have a file with new employees of Steel Wheels.
You have to insert those employees in the database. The file also contains old employees that have changed either the office where they work, or the extension number, or other basic information. You will take the opportunity to update that information as well. Take a look at the file you will use: In particular execute these statements: Create a transformation and use a Text File input step to read the file employees. Provide the name and location of the file, specify comma as the separator, and fill in the Fields grid.
Remember that you can quickly fill the grid by pressing the Get Fields button. As target table type employees. Fill the grids as shown: Save and run the transformation. Explore the employees table. You will see that one employee was updated, two were inserted, and one remained untouched because the file had the same data as the database for that employee: For each row in your stream, Kettle looks for a row in the table that matches the condition you put in the upper grid, the grid labeled The key s to look up the value s:.
Take for example the last row in your input file: It doesn't find one. Consequently, it inserts a row following the directions you put in the lower grid.
Then, it updates that row according to what you put in the lower grid. It only updates the columns where you put Y under the Update column. If you run the transformation with log level Detailed, you will be able to see in the log the real prepared statements that Kettle performs when inserting or updating rows in a table. Here there are two alternative solutions to this use case.
This would be faster because you would be avoiding unnecessary lookup operations. The Table Output step is really simply to configure: Just select the database connection and the table where you want to insert the records.
If the names of the fields coming to the Table Output step have the same name as the columns in the table, you are done. In order to handle the error when creating the hop from the Table Output step towards the Update step, select the Error handling of step option.
Alternatively right-click the Table Output step, select Define error handling Your transformation would look like this: Finally, fill the lower grid with those fields that you want to update, that is, those rows that had Y under the Update column.
In this case, Kettle tries to insert all records coming to the Table Output step. The rows for which the insert fails go to the Update step, and the rows are updated. The Table Output would insert all the rows. Those that already existed would be duplicated instead of updated. In general, for best practices reasons, this is not an advisable solution. If the table where you have to insert data defines a primary key, you should generate it.
This recipe explains how to do it when the primary key is a simple sequence. Same as the previous bullet, but in this case the primary key is based on stored values. Inserting new rows where a simple primary key has to be generated It's very common to have tables in a database where the values for the primary key column can be generated by using a database sequence in those DBMS that have that feature; for example, Oracle or simply by adding 1 to the maximum value in the table.
Loading data into these tables is very simple. This recipe teaches you how to do this through the following exercise. There are new offices at Steel Wheels. You have the data of the offices in a file that looks like this: Getting ready For this recipe you will use the Pentaho sample database. If you don't have that database, you'll have to follow the instructions in the introduction of this chapter. As you will insert records into the office table, it would be good if you explore that table before doing any insert operations.
Here you have a sample query: Create a transformation and create a connection to the sampledata database. Use a Text file input step to read the offices. Double-click the step, select the connection to the sampledata database, and type offices as the Target table.
Pentaho Data Integration 4 Cookbook
Fill the Key fields grid as shown: For the Creation of technical key fields leave the default values. From the Output category of steps, add an Update step. It's time to save the transformation and run it to see what happens. As you might guess, three new offices have been added, with primary keys 8, 9, and Look at the results: In many situations, before inserting data into a table you have to generate the primary key.
Because the offices are new, there aren't offices in the table with the same combination of address, city, and country values the lookup fails. Then, it inserts a row with the generated primary key and the fields you typed in the grid. Finally, the step adds to the stream the generated primary key value.
As a last task, we used that key to update the other fields coming into the file: But as you could see, it can also be used in the particular situation where you have to generate a primary key. In the recipe you generated the PK as the maximum plus one, but as you can see in the setting window, a database sequence can also be used instead.
Now suppose that you have a row that existed in the table. In that case the lookup would have succeeded and the step wouldn't have inserted a new row. That field would have been added to the stream, ready to be used further in the transformation, for example for updating other fields as you did in the recipe, or for being used for inserting data in a related table.
Note that this is a potentially slow step, as it uses all the values for the comparison. See also f Inserting new rows when the primary key has to be generated based on stored values. This recipe explains the case where the primary key to be generated is not as simple as adding one to the last primary key in the table.
Inserting new rows where the primary key has to be generated based on stored values There are tables where the primary key is not a database sequence, nor a consecutive integer, but a column which is built based on a rule or pattern that depends on the keys already inserted.
For example imagine a table where the values for primary key are A, A, and A In this case, you can guess the rule: The next in the sequence would be A This seems too simple, but doing it in PDI is not trivial.
This recipe will teach you how to load a table where a primary key has to be generated based on existing rows as in that example. Suppose that you have to load author data into the book's database. You have the main data for the authors, and you have to generate the primary key as in the example above.
Getting ready Run the script that creates and loads data into the book's database. You'll find it at http: Create a transformation and create a connection to the book's database. Use a Text file input step to read the authors. For simplicity, the authors.
To generate the next primary key, you need to know the current maximum. So use a Table Input step to get it. In this case the following statement will give you that number: You will have a simple clear transformation, but it will take several Kettle steps to do it.
By using a Join Rows cartesian product step, join both streams. Your transformation should look like this: Add an Add sequence step. For the rest of the fields in the setting window leave the default values. Add a Calculator step to build the keys. You do it by filling the setting window as shown: In order to insert the rows, add a Table output step, double-click it, and select the connection to the book's database.
As Target table type authors. Check the option Specify database fields. Select the Database fields tab and fill the grid as follows: Explore the authors table. You should see the new authors: When you have to generate a primary key based on the existing primary keys, unless the new primary key is simple to generate by adding one to the maximum, there is no direct way to do it in Kettle.
One possible solution is the one shown in the recipe: Getting the last primary key in the table, combining it with your main stream, and using those two sources for generating the new primary keys.
This is how it worked in this example.
Buy for others
First, by using a Table Input step, you found out the last primary key in the table. In fact, you got only the numeric part needed to build the new key. In this exercise, the value was 9.
With the Join Rows cartesian product step, you added that value as a new column in your main stream. Taking that number as a starting point, you needed to build the new primary keys as A, A, and so on. Then it converts the result to a String giving it the format with the mask This led to the values , , and so on.
It concatenates the literal A with the previously calculated ID. Note that this approach works as long as you have a single user scenario. If you run multiple instances of the transformation they can select the same maximum value, and try to insert rows with the same PK leading to a primary key constraint violation. The key in this exercise is to get the last or maximum primary key in the table, join it to your main stream, and use that data to build the new key.
After the join, the mechanism for building the final key would depend on your particular case. See also f Inserting new rows when a simple primary key has to be generated. If the primary key to be generated is simply a sequence, it is recommended to examine this recipe.
If the operation to do is simple, for example: If you face the second of the above situations, you can even use a Truncate table job entry. For more complex situations you should use the Delete step.
Let's suppose the following situation: You have a database with outdoor products. Each product belongs to a category: Getting ready In order to follow the recipe, you should download the material for this chapter: After creating the outdoor database and loading data by running the script provided, and before following the recipe you can explore the database.
In particular execute the following statement: The value to which you will compare the price before deleting will be stored as a named parameter. Drag to the canvas an Excel Input step to read the Excel file with the list of categories. After that, add a Database lookup step.
So far, the transformation looks like this: For higher volumes it's better to get the variable just once in a separate stream and join the two streams with a Join Rows cartesian product step. Select the Database lookup step and do a preview. You should see this: Finally, add a Delete step. You will find it under the Output category of steps. Double-click the Delete step, select the outdoor connection, and fill in the key grid as follows: Explore the database.
This is what you will see: The Delete step allows you to delete rows in a table in a database based on certain conditions. In this case, you intended to delete rows from the table products where the price was less than or equal to 50, and the category was in a list of categories, so the Delete step is the right choice. This is how it works. Then, for each row in your stream, PDI binds the values of the row to the variables in the prepared statement.
Let's see it by example. In the transformation you built a stream where each row had a single category and the value for the price. If you run the transformation with log level Detailed and look at the log, you will see the statement that is executed: Note that the conditions in the Delete step are based on fields in the same table. In this case, as you were provided with category descriptions and the products table does not have the descriptions but the ID for the categories, you had to use an extra step to get that ID: Suppose that the first row in the Excel file had the value tents.
As the ID for the category tents is 4, the execution of the prepared statement with the values in this row has the same effect as the execution of the following SQL statement: Refer to this recipe if you need to understand how the Database lookup step works. These are some use cases: In this case, suppose that you received a file with data about countries and the languages spoken in those countries. You need to load the full content into a temporary table. The table doesn't exist and you have to create it based on the content of the file.
Getting ready In order to follow the instructions, you will need the countries. Create a transformation and create a connection to the database where you will save the data. In order to read the countries.
Fill the Fields grid as follows: The symbol preceding the field isofficial is optional. By selecting Attribute as Element Kettle automatically understands that this is an attribute. From the Output category, drag and drop a Table Output step. Create a hop from the Get data from XML step to this new step. Double-click the Table Output step and select the connection you just created.
Click on the SQL button. A window will appear with the following script: After clicking on Execute, a window will show up telling that the statement has been executed, that is, the table has been created. All the information coming from the XML file is saved into the table just created. PDI allows you to create or alter tables in your databases depending on the tasks implemented in your transformations or jobs.
To understand what this is about, let's explain the previous example. The insert is made based on the data coming to the Table Output and the data you put in the Table Output configuration window, for example the name of the table or the mapping of the fields. Kettle builds the statements needed to execute that insert successfully. When the window with the generated statement appeared, you executed it. This causes the table to be created, so you could safely run the transformation and insert into the new table the data coming from the file to the step.
The SQL button is present in several database-related steps. In all cases its purpose is the same: Determine the statements to be executed in order to run the transformation successfully. These are some examples: Note that in this case the execution of the statement is not mandatory but recommended. You can execute the SQL as it is generated, you can modify it before executing it as you did in the recipe , or you can just ignore it.
Sometimes the SQL generated includes dropping a column just because the column exists in the table but is not used in the transformation. In that case you shouldn't execute it. Read the generated statement carefully, before executing it.
Finally, you must know that if you run the statement from outside Spoon, in order to see the changes inside the tool you either have to clear the cache by right-clicking the database connection and selecting the Clear DB Cache option, or restart Spoon.
See also f 36 Creating or altering a database table from PDI runtime. Instead of doing these operations from Spoon during design time, you can do them at runtime. This recipe explains the details. Chapter 1 Creating or altering a database table from PDI runtime When you are developing with PDI, you know or have the means to find out if the tables you need exist or not, and if they have all the columns you will read or update.
If they don't exist or don't meet your requirements, you can create or modify them, and then proceed. Assume the following scenarios: The table exists but you need to add some new columns to it before proceeding. This task is part of a new requirement, so this table doesn't exist.
While you are creating the transformations and jobs, you have the chance to create or modify those tables. But if these transformations and jobs are to be run in batch mode in a different environment, nobody will be there to do these verifications or create or modify the tables.
You need to adapt your work so these things are done automatically. Suppose that you need to do some calculations and store the results in a temporary table that will be used later in another process.
As this is a new requirement, it is likely that the table doesn't exist in the target database. You can create a job that takes care of this.
Create a job, and add a Start job entry. Link all the entries as shown: Please review and fix it if needed because you are using a different DBMS. Save the job and run it. Run the job again. Nothing should happen. The Table exists entry, as implied by its name, verifies if a table exists in your database. As with any job entry, this entry either succeeds or fails. If it fails, the job creates the table with an SQL entry.
If it succeeds, the job does nothing. The SQL entry is very useful not only for creating tables as you did in the recipe, but also for executing very simple statements, as for example setting a flag before or after running a transformation.
Its main use, however, is executing DDL statements. On the other side, in order to decide if it was necessary to create the table or not, you used a Table exists entry. In addition to this entry and before verifying the existence of the table, you could have used the Check Db connections.
This entry allows you to see if the database is available. Now, let's suppose the table exists, but it is an old version that doesn't have all the columns you need. In this case you can use an extra useful entry: Columns exist in a table. If you can detect that a column is not present, you can alter the table by adding that column, also with an SQL job entry.
Creating or altering tables is not a task that should be done as part of an ETL process. Kettle allows you to do it but you should be careful when using these features. Instead of doing these operations at runtime, you can do it from Spoon while you are designing the jobs and transformations. Inserting, deleting, or updating a table depending on a field PDI allows you to do the basic operations that modify the data in your tables, that is: For each of those operations you have at least one step that allows you to do the task.
It may happen that you have to do one or another operation depending on the value of a field. That is possible with a rather unknown step named Synchronize after merge.
Suppose you have a database with books. You received a file with a list of books. In that list there are books you already have, and there are books you don't have. For the books you already have, you intend to update the prices. Among the other books, you will insert in your database only those which have been published recently. You will recognize them because they have the text NEW in the comment field. As the recipe will modify the data in the database, before proceeding, explore the database to see what is inside.
In particular run these statements and pay attention to the results: Create a new transformation, and create a connection to the book's database. As separator, type. Read all fields as String except the price that has to be read as a Number with 0. Do a preview to verify you have read the file properly.
Use a Split Fields step to split the name field into two: Use a Database lookup step to look up in the authors table for an author that matches the firstname and lastname fields.
As Values to return from the lookup table: Check the option Do not pass the row if the lookup fails and close the window. Your transformation looks like this: Chapter 1 8. Double-click the step. As Connection, select the connection you just created. As Target table, type books. Remember that you can avoid typing by clicking on the Get Fields and Get update fields buttons to the right.
Select the Advanced tab. As Operation fieldname, select comment. As Insert when value equal, type NEW. As Update when value equal, type In Stock. Leave the other fields blank. Close the window and save the transformation. Run the transformation. Explore the database again. In particular, run for the second time the same statements you ran before doing the recipe. Now you will get this: The Synchronize after merge step allows you to insert, update, or delete rows in a table based on the value of a field in the stream.
In the recipe, you used the Synchronize after merge step both for inserting the new books for example, Mockingjay and for updating the prices for the books you already had for example, The Girl with the Dragon Tattoo.
In order to tell PDI whether to execute an insert or an update, you used the field comment.
Note that, because you didn't intend to delete rows, you left the Delete when value equal option blank. However, you could also have configured this option in the same way you configured the others. An example of that could be deleting the books that will stop being published. If you recognize those books after the expression out of market, you could type that expression in the Delete when value equal option and those books would be deleted.
Let's see a little more about the step you used in this recipe. It allows you to insert, update, and delete rows from a table all in a single step, based on a field present in the dataset. For each row Kettle uses the value of that column to decide which of the three basic operations to execute.
This happens as follows. Suppose that the Operation fieldname is called op and the values that should cause an insert, update, or delete are NEW, In Stock, and Discontinued respectively. The update is made for all rows where the field op is equal to the value In Stock. The delete is made for all rows where the field op is equal to the value Discontinued. The delete is made based on the key fields just like in a Delete step.
For Delete operations the content of the lower grid is ignored. Synchronizing after merge You may wonder what the name Synchronize after merge has to do with this, if you neither merged nor synchronized anything. The fact is that the step was named after the Merge Rows diff step, as those steps can perfectly be used together. The Merge Rows diff step has the ability to find differences between two streams, and those differences are used later to update a table by using a Synchronize after merge step.
See also f Deleting data from a table. For understanding how the delete operations work. Inserting or updating rows in a table and for understanding how the inserts and updates work. For learning to use the Synchronize after merge step along with the Merge Rows dif step.
Changing the database connection at runtime Sometimes you have several databases with exactly the same structure serving different purposes. These are some situations: In any of those situations, it's likely that you need access to one or the other depending on certain conditions, or you may even have to access all of them one after the other. Not only that, the number of databases may not be fixed; it may change over time for example, when a new branch is opened.
Suppose you face the second scenario: Your company has several branches, and the sales for each branch are stored in a different database. The database structure is the same for all branches; the only difference is that each of them holds different data. Now you want to generate a file with the total sales for the current year in every branch. Getting ready Download the material for this recipe. You will find a sample file with database connections to three branches.
It looks like this: Create a transformation that reads the file with connection data and copy the rows to results. Create a second transformation, and define the following named parameters: Create a database connection. Choose the proper Connection Type: Type a value for the Port Number: As Host Name: Use a Table Input step for getting the total sales from the database.
Use the connection just defined. Use a Text file output step for sending the sales summary to a text file. Don't forget to check the option Append under the Content tab of the setting window. Create a job with two Transformation job entries, linked one after the other. The job looks like this: Double-click the second transformation entry, select the Advanced tab, and check the Copy previous results to parameters?
Select the Parameters tab and fill it as shown: Save both transformations. Save the job, and run it. Open the text file generated. It should have one line with sales information for each database in the file with the list of databases.
If you have to connect to several databases, and you don't know in advance which or how many databases you will have to connect to, you can't rely on a connection with fixed values, or variables defined in a single place as for example in the kettle. In those situations, the best you could do is to define a connection with variables, and set the values for the variables at runtime. In the recipe, you created a text file with a summary sales line for each database in a list.
The transformation that wrote the sales line used a connection with variables defined as named parameters. This means that whoever calls the transformation has to provide the proper values. The main job loops on the list of database connections. For each row in that list, it calls the transformation copying the values from the file to the parameters in the transformation.
In other words, each time the transformation runs, the named parameters are instantiated with the values coming from the file. In the recipe, you changed the host and the name of the database. You could have parameterized any of the values that made up a database connection, for example the user and password. See also f Connecting to a database.
This recipe explains how to connect to a database by using variables. With this recipe you will understand better the way the loop over the database connection works. Loading a parent-child table A parent-child table is a table in which there is a self-referencing relationship. In other words, there is a hierarchical relationship among its rows.
A typical example of this is a table with employees, in which one of the columns contains references to the employee that is above each employee in the hierarchy. In this recipe you will load the parent-child table of employees of Steel Wheels. The hierarchy of roles in Steel Wheels is as follows: There is a single employee with this role. You will load all employees from a file. These are sample rows in that file: Getting ready In order to run this recipe, either truncate the employees table in Steel Wheels, or create the table employees in a different database.
Create a transformation that inserts the record for the president who is the first in the hierarchy, and doesn't report to anyone. Create another transformation to load the rest of the employees. Use a Text file input step to read the file of employees.
Add a Filter rows step to filter the employees to load based on their role. In order to do that, enter the following condition: Add a Database lookup to find out the employee number of the employee who is one above in the hierarchy: Add a Table Output step, and use it to insert the records in the table employees.
Your final transformation looks like this: Finally create a job to put all together. Link all of them in a row. Use the first Transformation entry to execute the transformation that loads the president. Double-click the second Transformation entry and configure it to run the transformation that loads the other employees. Repeat step 10 for the third Transformation entry, but this time type. Repeat step 10 for the fourth Transformation entry, but this time type Sales Rep.
Save and run the job. The table should have all employees loaded, as you can see below: If you have to load a table with parent-child relationships, loading all at once is not always feasible. Look at the sampledata database. We loaded all employees, one role at a time, beginning by the president and followed by the roles below in the hierarchy.
The transformation that loaded the other roles simply read the file, kept only the employees with the role being loaded, looked for the ID of the parent employee in the hierarchy, and inserted the records.
For the roles you could have used fixed values but you used regular expressions instead. In doing so, you avoided calling the transformation once for each different role. For example, for loading the vice-presidents you called the transformation once with the regular expression VP.
See also f Inserting or updating rows in a table. If you are not confident with inserting data into a table see this recipe.
PDI has the ability to read data from all kind of files and different formats. It also allows you to write back to files in different formats as well. Reading and Writing Files Reading and writing simple files is a very straightforward task.
There are several steps under the input and output categories of steps that allow you to do it. You pick the step, configure it quickly, and you are done. However, when the files you have to read or create are not simple—and that happens most of the time—the task of reading or writing can become a tedious exercise if you don't know the tricks. In this chapter, you will learn not only the basics for reading and writing files, but also all the how-tos for dealing with them. This chapter covers plain files txt, csv, fixed width and Excel files.
Reading a simple file In this recipe, you will learn the use of the Text file input step. In the example, you have to read a simple file with a list of authors' information like the following: Carry out the following steps: Create a new transformation. Drop a Text file input step to the canvas. Now, you have to type the name of the file authors.
You do it in the File or directory textbox. Alternatively, you can select the file by clicking on the Browse button and looking for the file. The textbox will be populated with the complete path of the file. Click on the Add button. The complete text will be moved from the File or directory textbox to the grid. Select the Content tab and fill in the required fields, as shown in the following screenshot: Select the Fields tab and click on the Get Fields button to get the definitions of the fields automatically.
The grid will be populated, as shown in the following screenshot: Kettle doesn't always guess the data types, size, or format as expected. So, after getting the fields, you may change the data to what you consider more appropriate. When you read a file, it's not mandatory to keep the names of the columns as they are in the file. You are free to change the names of the fields as well.
Click on the Preview button and you will see some sample rows built with the data in your file. You use the Text file input in order to read text files, in this case, the authors. Looking at the content of the file, you can see that the first line contains the header of the columns. In order to recognize that header, you have to check the Header checkbox under the Content tab, and type 1 in the Number of header lines textbox.
You also have to indicate the field's separator. The separator can be made of one or more characters the most used being the semicolon, colon, or a tab. Finally, you can indicate the Enclosure string, in this case, ". PDI takes all that information and uses it to parse the text file and fill the fields correctly.
To work with these kinds of delimited text files, you could choose the CSV file input step. This step has a less powerful configuration, but it provides better performance. If you explore the tabs of the Text file input setting window, you will see that there are more options to set, but the ones just explained are by far the most used. But there are a couple of additional features that may interest you: Alternative notation for a separator Instead of typing the separator for the fields, you can use the following notation: However, this notation makes more sense when your separators are non printable characters.
For the enclosure string the hexadecimal notation is also allowed. About file format and encoding If you are trying to read a file without success, and you have already checked the most common settings, that is, the name of the file, the header, the separator and the fields, you should take a look at and try to fix the other available settings.
Among those, you have Format and Encoding. Format allows you to specify the format of your file s: If your file has a Unix format, you should change this setting. If you don't know the format, but you cannot guarantee that the format will be DOS, you can choose the mixed option. Encoding allows you to specify the character encoding to use. If you leave it blank, Kettle will use the default encoding on your system. Alternatively, if you know the encoding and it is different from the default, you should select the proper option from the drop-down list.
About data types and formats When you read a file and tell Kettle which fields to get from that file, you have to provide at least a name and a data type for those fields. In order to tell Kettle how to read and interpret the data, you have more options. Most of them are self-explanatory, but the format, length, and precision deserve an explanation: If you are reading a number, and the numbers in your file have separators, dollar signs, and so on, you should specify a format to tell Kettle how to interpret that number.
Length is the total number of significant figures, while precision is the number of floating point digits. If you don't specify format, length, or precision, Kettle will do its best to interpret the number, but this could lead to unexpected results.
In the case of dates, the same thing happens. When your text file has a date, you have to select or type a format mask, so Kettle can recognize the different components of the date in the field. Suppose you want to move the country name to the end of the list of columns, changing it to a more suitable field name, such as nationality.
In this case, add a Select values step.
The Select values step allows you to select, rename, reorder, and delete fields, or change the metadata of a field. If you just want to rename the columns, you don't need a Select values step. You can do it in the Text file input step by typing the names manually. This is the default value for the type of file, as you can see under the Content tab.
You have another option here named Fixed for reading files with fixed-width columns. If you choose this option, a different helper GUI will appear when you click on the Get fields button. In the wizard, you can visually set the position for each of your fields. It provides better performance and has a simpler, but less flexible configuration.
Reading several files at the same time Sometimes you have several files to read, all with the same structure, but different data.
In this recipe, you will see how to read those files in a single step. The example uses a list of files containing names of museums in Italy. Getting ready You must have a group of text files in a directory, all with the same format. Each file has a list of names of museums, one museum on each line. Drop a Text file input step onto the work area. Under the File or directory tab, type the directory where the files are.
In the Regular Expression textbox, type: Then click on the Add button. Note that the variable will be undefined until you save the transformation. Therefore it's necessary that you save before running a preview of the step.
Under the Fields tab, add one row: Save the transformation in the same place, the museum directory is located. Previewing the step, you will obtain a dataset with the content of all files with names of museums. With Kettle, it is possible to read more than one file at a time using a single Text File Input step.
In order to get the content of several files, you can add names to the grid row by row. If the names of files share the path and some part of their names, you can also specify the names of the files by using regular expressions, as shown in the recipe.
If you enter a regular expression, Kettle will take all the files whose names match it. You can test if the regular expression is correct by clicking on the Show filename s … button.
That will show you a list of all files that matches the expression. If you fill the grid with the names of several files with or without using regular expressions , Kettle will create a dataset with the content of all of those files one after the other. To learn more about regular expressions, you can visit the following URLs: In the recipe, you read several files.
It might happen that you have to read just one file, but you don't know the exact name of the file. The recipe is useful in cases like that as well. In this example, if you don't know the name of the file, you will still be able to read it by typing the following regular expression: Reading unstructured files The simplest files for reading are those where all rows follow the same pattern: Each row has a fixed number of columns, and all columns have the same kind of data in every row. However, it is common to have files where the information does not have that format.
In many occasions, the files have little or no structure. Suppose you have a file with roller coaster descriptions, and the file looks like the following: Roller Coaster Stats Drop: Kraken begins with a plunge from a height of stories Roller Coaster Stats Height: As you can see, the preceding file is far from being a structured file that you can read simply by configuring a Text file input step.
Following this recipe, you will learn how to deal with this kind of file. Getting ready When you have to read an unstructured file, such as the preceding sample file, the first thing to do is to take a detailed look at it. Try to understand how the data is organized; despite being unstructured, it has a hidden format that you have to discover in order to be able to read it.
So, let's analyze the sample file, which is available for download from the book's site. The file has data about several roller coasters.
Let's take note of the characteristics of the file: As a useful exercise, you could do this yourself before reading the following list. It should be discarded.
There is nothing that distinguishes these lines. They simply do not fall into any of the other kinds of lines lines with the name of the park, lines with properties of the roller coaster, and so on.
Once you understand the content of your file, you are ready to read it, and parse it. Create a transformation and drag a Text file input step. Under the Content tab, uncheck the Header option and under the Separator tab, type. Under the Fields tab, enter a single field named text of type String. As the character is not present in any part of the file, you are sure that the whole line will be read as a single field. From the Scripting category of steps, add a Modified Java Script Value step, doubleclick it, and under the main tab window type the following snippet of code: Click on the Get variables button to populate the grid with the variable attraction.
From the Transform category, add an Add value fields changing sequence step. In the first row of the grid type attraction. Do a preview on this last step. You will see the following: So far, you've read the file, and identified all the rows belonging to each roller coaster.
It's time to parse the different lines. Then you will see different ways for searching data, executing and reusing jobs and transformations, and manipulating streams. Further, you will learn all the available options for integrating Kettle with other Pentaho tools. Pentaho Data Integration 4 Cookbook has plenty of recipes with easy step-by-step instructions to accomplish specific tasks. There are examples and code that are ready for adaptation to individual needs.
Evaluate Confluence today. Pentaho Community. Pages Blog. Space shortcuts File lists. Child pages. Pentaho Books. Pentaho Data Integration 4 Cookbook. Browse pages. Page History. Jira links. Created by Doug Moran , last modified on Feb 02, Approach This book has step-by-step instructions to solve data manipulation problems using PDI in the form of recipes.Any existing errata can be viewed by selecting your title from http: The recipe uses the UDJE for its simplicity and performance.
Press the Test button. Fill in the Fields tab. You need to load the full content into a temporary table. In the Settings frame specify the connection string which should be explained along with JDBC , the driver class name, and the username and password. Jan holds the degree of Commercial Engineer in international business affairs from the Catholic University of Leuven Belgium and extended his further knowledge in the field of business intelligence through a Masters in Artificial Intelligence.
Create a transformation.
- THE SHADOW OF THE WIND EBOOK
- OBJECT FIRST WITH JAVA EBOOK
- NURSING DIAGNOSIS EBOOK
- ANNA AND THE KING OF SIAM EBOOK
- LIVRO VIDAS SECAS EBOOK
- JOHN RAWLS A THEORY OF JUSTICE EBOOK
- PEAK ERECTILE STRENGTH DIET EBOOK
- CHEMICAL REACTION ENGINEERING FOGLER EBOOK
- EBOOK NOVEL 9 SUMMER 10 AUTUMNS
- LIVROS DE AUGUSTO CURY EM PDF PARA