The MaxCompute Graph SDK for Java provides the classes you need to build, configure, and submit graph processing jobs on MaxCompute. Each class plays a specific role and is registered on a central GraphJob object before the job is submitted.
Add the Maven dependency
Search for odps-sdk-graph in the Maven repository to find the latest version, then declare the dependency in your project:
<dependency>
<groupId>com.aliyun.odps</groupId>
<artifactId>odps-sdk-graph</artifactId>
<version>0.20.7-public</version>
</dependency>SDK classes
| Class | Description | GraphJob configuration method |
|---|---|---|
GraphJob | Defines, submits, and manages a graph job. Inherits JobConf. | — (entry point) |
Vertex | Defines a vertex. Properties: id, value, halted, edges. | setVertexClass |
Edge | Defines an edge. Properties: destVertexId, value. MaxCompute Graph uses the adjacency list — a vertex's outbound edges are stored in its edges property. | Defined as part of Vertex |
GraphLoader | Loads a graph. | setGraphLoaderClass |
VertexResolver | Handles conflicts during graph topology modification. Register separate instances for graph loading and iterative computing. | setLoadingVertexResolverClass, setComputingVertexResolverClass |
Partitioner | Distributes vertices across workers to enable parallel computing. The default HashPartitioner assigns each vertex by computing hash(vertexId) % numWorkers. | setPartitionerClass |
WorkerComputer | Runs custom logic when a worker starts and stops — useful for initializing shared state or flushing results. | setWorkerComputerClass |
Aggregator | Processes and summarizes global information across all workers. You can register multiple Aggregator classes in the same job. | setAggregatorClass(Class…) |
Combiner | Summarizes the output records with the same key. | setCombinerClass |
Counters | Tracks counts across workers. Get a Counters instance from WorkerContext and increment it; the framework sums values across all workers automatically. | Accessed via WorkerContext |
WorkerContext | Provides access to all framework features within a superstep: modify graph topology, send messages, write results, and read resources. | Injected by the framework |
该文章对您有帮助吗?