This topic describes how to build a MapReduce program in DataWorks by using the WordCount example program.

Create a project

  1. Log on to the DataWorks console. Click Workspaces in the left-side navigation pane. On the Workspaces page, find the target workspace and click Data Analytics in the Actions column.
  2. On the DataStudio page that appears, click the DataWorks icon in the upper-left corner and choose All Products > Function Studio.
  3. On the Function Studio page that appears, click Projects in the left-side navigation pane. On the Projects page, click Create Project from Code.
  4. On the Create Project page that appears, enter the name and description for the project and select the runtime environment. In this example, select UDFJava Project.
  5. After the preceding configuration is completed, click Submit. Then, you are redirected to the Function Studio page.

Write a program

In the left-side navigation pane of the Function Studio page, double-click in the src/main/java/ directory. The sample code for the WordCount program appears on the right.

The sample code is designed to count the number of occurrences of each word in an input table and write the count result to another table, which is the output table.

Debug the program

You cannot debug MapReduce programs in Function Studio. To debug a MapReduce program, commit the resource to the development environment and verify the code logic in DataStudio.

Note Currently, Function Studio only allows you to write code or compile and package code.

Deploy the program

  1. To compile and package the code to a JAR package in Function Studio and commit the JAR package as a resource to the development environment in DataStudio, follow these steps:
    1. Move the pointer over the Commit the resource icon on the Function Studio page and click Submit Resource to Development Environment.
    2. In the Submit Resource to DataStudio Development Environment dialog box that appears, select the destination workspace and destination workflow and enter the resource name. In this example, the resource name is WordCountDemo_1.0.0.jar.
    3. Select or clear the Force Overwrite check box as required. By default, this check box is selected. Then, click OK.
    4. After the resource is committed, the URL of the resource in DataStudio appears on the Output tab. Enter the URL in a browser to go to the Resource page of DataStudio, where you can find the committed resource.
  2. To create an ODPS MR node in DataStudio, follow these steps:
    1. On the DataStudio page, find and open the target workflow in the left-side navigation pane.
    2. Right-click Data Analytics and choose Create Data Analytics Node > ODPS MR.
    3. In the code editor of the ODPS MR node, write the following code to create an input table and an output table and insert test data into the input table:
      --Create an input table.
      create table if not exists wc_input (key string,value string);
      --Create an output table.
      create table if not exists wc_out (key string,cnt bigint);
      --Insert data into the input table.
      insert overwrite table wc_input values ('hello','odps');
    4. Right-click the resource of the WordCount program and select Insert Resource Path. Then, the following statement appears in the code editor of the ODPS MR node: --@resource_reference{"WordCountDemo_1.0.0.jar"}.
    5. Set the jar -resources and -classpath parameters for the referenced resource in the code. Use the following sample code:
      jar -resources WordCountDemo_1.0.0.jar 
      -classpath . /WordCountDemo_1.0.0.jar wc_input wc_out
    6. Click the Run icon in the top navigation bar of the code editor.
  3. Click Properties in the right-side navigation pane. On the Properties tab that appears, set the relevant parameters.
  4. After the scheduling configuration is completed, click the Save icon and then the Submit icon or the Commit and Unlock icon in the top navigation bar of the code editor. The ODPS MR node is committed to the development environment.
  5. Deploy the ODPS MR node to the production environment. For more information, see Deploy a node.
  6. Run the ODPS MR node in the production environment to debug the WordCount program. For more information, see Auto triggered nodes.