本文将以单源最短距离(Single Source Shortest Path,SSSP)算法为例,为您介绍如何提交Graph作业。
Graph作业的提交方式与MapReduce的提交方式基本相同。
前提条件
- 编写、编译、运行MapReduce前,需要首先安装JDK 1.6或以上版本。
说明 如果您使用Maven,可以从Maven 库中搜索odps-sdk-mapred获取不同版本的Java SDK,相关配置信息如下所示。
<dependency> <groupId>com.aliyun.odps</groupId> <artifactId>odps-sdk-mapred</artifactId> <version>0.26.2-public</version> </dependency>
- 请参见安装并配置客户端对MaxCompute客户端进行部署。更多关于MaxCompute客户端的使用,请参见MaxCompute客户端。
操作步骤
- 运行MaxCompute客户端。
- 执行如下命令创建输入表sssp_in和输出表sssp_out 。
CREATE TABLE sssp_in (v bigint, es string); CREATE TABLE sssp_out (v bigint, l bigint);
创建表的更多语句请参见表操作。
- 上传数据至表sssp_in中。
示例数据如下,建议您创建sssp.txt文件将数据保存至本地。假设保存在本地路径为D:\
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
执行Tunnel命令上传数据至表sssp_in中, 以空格键做两列的分隔符。tunnel u -fd " " D:\sssp.txt sssp_in;
- 编写SSSP示例。
本地编译、调试SSSP算法示例,假设代码被打包为名为odps-graph-example-sssp.jar的文件。说明 仅需要将SSSP代码打包即可,不需要同时将SDK打包入odps-graph-example-sssp.jar中。
- 添加Jar资源。 更多添加资源的信息,请参见资源操作。
add jar $LOCAL_JAR_PATH/odps-graph-example-sssp.jar;
- 运行SSSP。
jar -libjars odps-graph-example-sssp.jar -classpath $LOCAL_JAR_PATH/odps-graph-example-sssp.jar com.aliyun.odps.graph.example.SSSP 1 sssp_in sssp_out;
Graph作业执行时命令行会打印作业实例ID、执行进度、结果Summary等,输出示例如下所示。ID = 20130730160742915g****** 2013-07-31 00:18:36 SUCCESS Summary: Graph Input/Output Total input bytes=211 Total input records=5 Total output bytes=161 Total output records=5 graph_input_[bsp.sssp_in]_bytes=211 graph_input_[bsp.sssp_in]_records=5 graph_output_[bsp.sssp_out]_bytes=161 graph_output_[bsp.sssp_out]_records=5 Graph Statistics Total edges=14 Total halted vertices=5 Total sent messages=28 Total supersteps=4 Total vertices=5 Total workers=1 Graph Timers Average superstep time (milliseconds)=7 Load time (milliseconds)=8 Max superstep time (milliseconds) =14 Max time superstep=0 Min superstep time (milliseconds)=5 Min time superstep=2 Setup time (milliseconds)=277 Shutdown time (milliseconds)=20 Total superstep time (milliseconds)=30 Total time (milliseconds)=344 OK
说明 如果您需要使用Graph功能,直接提交图计算作业即可。
在文档使用中是否遇到以下问题
更多建议
匿名提交