This topic describes how to submit a Graph job. In this topic, the single source shortest path (SSSP) algorithm is used as an example.
- The MaxCompute client is installed and configured.
For more information about how to install and configure the MaxCompute client, see MaxCompute client.
- MaxCompute Studio is installed and configured.
- Java Development Kit (JDK) 1.8 or later is installed.
- A data file is prepared. The sssp.txt file is used in this example. The sssp.txt file
contains the following data:
1 2:2,3:1,4:4 2 1:2,3:2,4:1 3 1:1,2:2,5:1 4 1:4,2:1,5:1 5 3:1,4:1
- Run the MaxCompute client and execute the following statements to create an input
table named sssp_in and an output table named sssp_out.
CREATE TABLE sssp_in (v bigint, es string); CREATE TABLE sssp_out (vertex bigint, value bigint);Note For more information about how to create a table, see Table operations.
- Run the Tunnel command to upload data in the sssp.txt file to the sssp_in table. Separate data in different columns with spaces.
tunnel u -fd " " sssp.txt sssp_in;Note In this example, the sssp.txt file is stored in the
bindirectory of the MaxCompute client. Take note of the actual directory in which the file is stored.
- Write SSSP code.
- Create a MaxCompute Java module named odps-graph-example-sssp in IntelliJ IDEA.
- Create the
BaseLoadingVertexResolverclass and the
SSSPclass in odps-graph-example-sssp. For more information about how to create a class, see the sample code for the directed graph that is provided in SSSP.
- In IntelliJ IDEA, package the Java program into a JAR file by using MaxCompute Studio.
For more information about how to package a Java program into a JAR file, see Package a Java program, upload the package, and create a MaxCompute UDF. Note In this example, the JAR package that is deployed in the MaxCompute project is named odps-graph-example-sssp.jar.
- Run the following command on the MaxCompute client to implement the SSSP algorithm:
jar -libjars odps-graph-example-sssp.jar -classpath <LOCAL_JAR_PATH>/odps-graph-example-sssp.jar SSSP 1 sssp_in sssp_out;
LOCAL_JAR_PATH: indicates the local path of the odps-graph-example-sssp.jar package.The following result is returned:
vertex value 1 0 2 2 3 1 4 3 5 2
Note If you want to use the Graph feature, you can directly submit a Graph job.
- vertex: indicates the current vertex.
- value: indicates the value of the SSSP from the current vertex to Source Vertex 1.