All Products
Search
Document Center

MaxCompute:Develop a graph program

Last Updated:Jun 20, 2026

This topic describes how to develop a graph program in MaxCompute Studio. The process includes writing, debugging, packaging, uploading, and running the program.

Prerequisites

Complete the following tasks:

  1. Manage project connections

  2. Create a MaxCompute Java module

Write a graph program

  • Create a MaxCompute Java class.

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

    1. In the Project pane, right-click the source code directory of the module (that is, src > main > java), and select New > MaxCompute Java.

    2. Enter a Name, select GraphLoader or Vertex as the type, and then press Enter.

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

        Note

        If you have not created a package, enter packagename.classname. The package is automatically created.

      • Select GraphLoader or Vertex. The following list describes the types:

        • GraphLoader: Used to load a graph. Use the setGraphLoaderClass interface of GraphJob to provide a GraphLoader implementation.

        • Vertex: An abstraction of a graph vertex. It includes the following properties: id, value, halted, and edges. Use the setVertexClass interface of GraphJob to provide a Vertex implementation.

    3. After the class is created, develop the Java program in the editor. For sample code for the BaseLoadingVertexResolver class and the SSSP class, see SSSP.

  • Add the required dependencies to your pom.xml file.

    <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>
    <!-- For local testing -->
    <dependency>
        <groupId>com.aliyun.odps</groupId>
        <artifactId>odps-graph-local</artifactId>
        <version>0.48.0-public</version>
    </dependency>

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

Debug with a local run

Run the graph program locally to verify that the output meets your expectations.

  1. Right-click the Java file and select Run.

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

    For the MaxCompute project, select local from the drop-down list on the left and the target project, such as example_project, from the one on the right.

    • MaxCompute project: The project where you will run the graph program.

    • Download Record limit: The maximum number of records to download. The default is 100.

  3. Click OK to start the run.

    For a local run, the program reads data from the specified table in the warehouse directory as input. You can view the log output in the console. For more information about the warehouse directory, see warehouse directory.

Package and upload

After you debug the program, package it into a JAR file and upload it to MaxCompute as a resource. For more information, see Package, upload, and register.

Run the graph program

  1. In the left navigation pane of IntelliJ IDEA, open the Project pane.

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

  3. In the Console pane, run the graph program. The following command is provided as an example. Before you run the command, replace the main class, input table, and output table with your actual values.

    For more commands, see JAR commands.

    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.