All Products
Search
Document Center

MaxCompute:Develop Graph programs

Last Updated:Nov 08, 2024

This topic describes how to use MaxCompute Studio to develop Graph programs. This helps you learn about how to write, debug, package, upload, and run Graph programs.

Prerequisites

The following prerequisites are met:

Write a Graph program

  • Create a MaxCompute Java Class.

    This topic uses the creation of the BaseLoadingVertexResolver class and the SSSP class as examples.

    1. In the left-side navigation pane of the Project tab, choose src > main > java, right-click java, and then choose New > MaxCompute Java.

      11

    2. Specify Name, select GraphLoader or Vertex, and then press Enter.

      新建Class

      • Name: the name of the MaxCompute Java class that you want to create.

        Note

        If no package is created, enter packagename.classname. The system automatically creates a package.

      • Select GraphLoader or Vertex as the class type.

        Note
        • GraphLoader: loads a graph. You can specify this class by using the setGraphLoaderClass method of GraphJob.

        • Vertex: defines a vertex in a graph. A vertex has the following properties: id, value, halted, and edges. You can specify this class by using the setVertexClass method of GraphJob.

    3. After you create a MaxCompute Java class, develop a Java program in the editor. For more details about the BaseLoadingVertexResolver class and the SSSP class, see SSSP.

  • Configure the pom.xml file. The following code shows the dependencies that you must import:

    <dependency>
        <groupId>com.aliyun.odps</groupId>
        <artifactId>odps-sdk-core</artifactId>
        <version>0.48.0-public</version>
    </dependency>
    <dependency>
        <groupId>com.aliyun.odps</groupId>
        <artifactId>odps-sdk-graph</artifactId>
        <version>0.48.0-public</version>
    </dependency>
    
    <!-- used for local test -->
    <dependency>
        <groupId>com.aliyun.odps</groupId>
        <artifactId>odps-graph-local</artifactId>
        <version>0.48.0-public</version>
    </dependency>

    After you finish configuring the pom.xml file, you can verify that the dependencies are loaded successfully in the Maven pane.

Debug the Graph program

Locally run the Graph program and check whether the results meet your expectation.

  1. Right-click the Java script that you wrote and select Run.

  2. In the Run/Debug Configurations dialog box, configure the runtime parameters.

    graph

    • MaxCompute project: the MaxCompute project in which you want to run the Graph program.

    • Download Record limit: the maximum number of records that can be downloaded. Default value: 100.

  3. Click OK to run the UDF.

    This topic chooses local execution, so the system reads data from the specified table in warehouse directory as the input. You can view the log output in the console. For more information about the warehouse, see Overview.

Package and upload a MapReduce program

After you debug the MapReduce program that you wrote, package the MapReduce program into a JAR file and upload the file to your MaxCompute project as a resource. For more information, see Package, upload, and register a Java program.

Run the Graph program

  1. In the left-side navigation pane of the IntelliJ IDEA tool, click Project Explorer.

  2. Right-click the name of your MaxCompute project and select Open in Console.

  3. In the Console section, run the following command. Replace PageRank, pagerank_in, and pagerank_out based on actual situations.

    For more commands, see Submit a MapReduce job.

    jar -libjars xxx.jar -classpath /Users/home/xxx.jar com.aliyun.odps.graph.examples.PageRank pagerank_in pagerank_out;
    • PageRank: the main class defined in the Graph program.

    • pagerank_in: the input table.

    • pagerank_out: the output table.