Create OPEN MR

Last Updated: Jul 06, 2017

Basic concepts of OPEN MR

This document aims to help users to use the MaxCompute MR feature in a safer and more convenient manner to implement more complicated computing logic. It focuses on development methods of OPEN MR to help users better develop complicated MR models.

OpenMR users only need to care about the Mapper/Reducer logic, and the job submission logic is handled uniformly by the platform.

Variables involved in some daily scheduling can be specified through parameters in the configuration when you create the OpenMR node.

Scenario and data description

This demo describes how to use MaxCompute MapReduce on Alibaba Cloud Data IDE with a classic WordCount example.

Data tables involved in this document are described as follows:

1) Input data table: “wc_in” is used to store the Word list.

2) Output data table: “wc_out” is used to store the result set processed by MapReduce.

Step 1: Prepare data tables

Creating data tables

Refer to Quick Start-New Table chapter to create the wc_in and wc_out tables.

  1. CREATE TABLE wc_in (key STRING, value STRING) partitioned by (pt string );
  2. CREATE TABLE wc_out (key STRING, cnt BIGINT) partitioned by (pt string );

Insert sample data

To detect the running results of OPEN MR on Alibaba Cloud Data IDE, you need to insert sample data to the input table (Partition pt=20170101 in the “wc_in” data table). The steps are as follows:

  1. Navigate to Data IDE, click New > New Script File.

  2. Fill in the configuration items in the New Script File pop-up box, and then click “Submit”.

    1

  3. Compile the MaxCompute SQL statement and run the code in the MaxCompute code editor.

    1

The MaxCompute SQL script is provided as follows:

  1. ---Create system dual
  2. drop table if exists dual;
  3. create table dual(id bigint); --If the project does not have this pseudo table, you should create it and initialize data.
  4. ---Initialize data to the pseudo table.
  5. insert overwrite table dual select count(*)from dual;
  6. ---Insert sample data into Partition pt=20170101 in the wc_in input table.
  7. insert overwrite table wc_in partition(pt=20170101) select * from (
  8. select 'project','val_pro' from dual
  9. union all
  10. select 'problem','val_pro' from dual
  11. union all
  12. select 'package','val_a' from dual
  13. union all
  14. select 'pad','val_a' from dual
  15. ) b;

You can preview the inserted sample data, as shown in the figure below:

1

Step 2: Compile MapReduce

Before using an OPEN MR node, you should compile the WordCount demo code based on the MaxCompute MapReduce framework in the local environment and compress the code into a JAR package, and add the package as a resource to Alibaba Cloud Data IDE.

For MR development, refer to the Help section on the MaxCompute official website. Link: MaxCompute Help Documents.

For details of the code in this example, seeWordCount.java appendix.

Step 3: Add a resource

You need to run the MaxCompute MR node in the MaxCompute console or Alibaba Cloud Data IDE by using the “jar” command. First, generate a WordCount.jar package (using the Export function of Eclipse, or using Ant or another tool), and then upload the package as an MaxCompute resource.

The specific steps are as follows:

  1. Select “Manage Resources” in the left catalog, and right click on the Upload Resources on the catalog.

  2. Fill in the configuration items in the Resource Upload pop-up box. Notice that you must check the ‘Upload as ODPS Resource’ box.

    1

  3. Click “Submit”.

Step 4: Create an OpenMR node

After the newly created MaxCompute MapReduce program is uploaded as a resource to MaxCompute, you need to create an MaxCompute MR node to run the program. The specific steps are as follows:

  1. Click New > New Job in the tool bar in the work zone.

  2. Fill in the various configuration items in the New Job pop-up box.

    1

    Configuration items in the “New Job” pop-up box are described as follows:

    ■ Job Name: wordcount demo.

    ■ Description: wordcount demo.

  3. Click “Create” ;

  4. Drag an OPEN MR node to the development canvas ;

    1

  5. Double click on the node, or right click to view the node content to enter the OPEN MR configuration page ;

    1

    1

    • MRJar package: required. The primary JAR resource package to be run by this node.
    • Resources: required. The primary JAR resource and the list of other resources called to be run by this node.
    • Input/Output Tables: In this demo, the partition table of this project is used and the partition value is the business date subject to daily automatic scheduling. Therefore, the partition is represented by a variable (system scheduling parameter).

    Parameter Configuration: The partition in this demo is represented by the system variable with no user-defined variables, so here no additional configurations are required:

    1

    Note: For more usage of parameter variables, refer to System Scheduling Parameters.

  6. Click Save, Submit and switch to the process panel of the workflow. Click “Test Run”. Note: In the test run, only the Partition pt=20170101 in the example table contains data, so 2017-01-01 is selected as the business time, so that the system parameters will replace the partitions in the input/output tables with 20170101.

    1

    1

    After the test job is generated, wait for the run to succeed.

Step 5: View the resource

To display the test results, take the following steps:

  1. Open “wc_in” and insert the sample data script file ;

  2. Compile the query MaxCompute SQL code ;

  3. Click “Run”.

    1

View whether the test results are consistent with expectations.

Thank you! We've received your feedback.