|Using Compression with Pentaho MapReduce||Advanced Pentaho MapReduce||Using a Custom Input or Output Format in Pentaho MapReduce|
How to use a custom partitioner in Pentaho MapReduce. In some situations you may wish to specify which reducer a particular key goes to. For example you are parsing a weblog, have a complex key containing IP address, year, and month and need all of the data for a year to go to a particular reducer. For more information on partitioners: http://developer.yahoo.com/hadoop/tutorial/module5.html#partitioning
In order to follow along with this how-to guide you will need the following:
- Pentaho Data Integration
- Pentaho Hadoop Distribution
The sample data file needed for this guide is:
|weblogs_parse.txt.zip||Parsed, raw weblog data|
Note: If you have already completed the Using Pentaho MapReduce to Parse Weblog Data guide the data should already be in the correct spot.
Add the file to your cluster by running the following:
This guide expands upon the Using Pentaho MapReduce to Generate an Aggregate Dataset guide. If you have completed this guide you should already have the necessary code, otherwise download aggregate_mapper.ktr, aggregate_reducer.ktr, and aggregate_mr.kjb.
Start Hadoop if it is not already running.
In this task you will create a Java partitioner that takes a key in the format client_ip tab year tab month and partition on the year.
You can download CustomPartitioner.jar containing the partitioner if you don't want to do every step
- Create Year Partitioner Class: In a text editor create a new file named YearPartitioner.java containing the following code:
- Compile the Class: Run the following command:
- Collect the Class into a Jar: Run the following command:
In this task you will deploy the custom partitioner to the cluster so it may be used in the Distributed Cache.
- Create a Directory: Create a directory to store the custom partitioner:
- Add the Custom Partitioner to the Cluster: Add the CustomPartitioner.jar to HDFS:
In this task you will configure the aggregate_mr.kjb job to use the custom partitioner.
You can download the already completed aggregate_mr_partition.kjb if you do not want to do every step
- Start PDI on your desktop. Once it is running choose 'File' -> 'Open', browse to and select the 'aggregate_mr.kjb', then click 'OK'.
- Configure Number of Reducers: Double click on the 'Pentaho MapReduce' job entry. Once it is open switch to the 'Cluster' tab and set 'Number of Reducer Tasks' to '3'.
- Configure Partitioner to Use: Switch to the User Defined tab and enter the following:
Name Value Explanation mapred.cache.files /distcache/CustomPartitioner.jar Adds the Custom Partitioner to the distributed cache for the job. mapred.job.classpath.files /distcache/CustomPartitioner.jar Adds the Custom Partitioner from the distributed cache to the java classpath for the job. mapred.partitioner.class YearPartitioner Tells the job to use the YearPartitioner class.
- Save the Job: Choose 'File' -> 'Save as...' from the menu system. Save the transformation as 'aggregate_mr_partition.kjb' into a folder of your choice.
- Run the Job: Choose 'Action' -> 'Run' from the menu system or click on the green run button on the job toolbar. A 'Execute a job' window will open. Click on the 'Launch' button. An 'Execution Results' panel will open at the bottom of the PDI window and it will show you the progress of the job as it runs. After a few seconds the job should finish successfully.
- View the first Output File: This command should return an empty file. There are only 2 years of data in the sample file, but you specified 3 reducers, therefore one reducer will receive no data.
- View the second Output File: This command should only return data for the year 2010.
- View the third Output File: This command should only return data for the year 2011.