本文向您介绍如何使用MaxCompute客户端运行和提交MapReduce作业。
MaxCompute客户端提供一个Jar命令用于运行MapReduce作业,具体语法如下所示:
jar [<GENERIC_OPTIONS>] <MAIN_CLASS> [ARGS];
-conf <configuration_file> Specify an application configuration file
-resources <resource_name_list> file\table resources used in mapper or reducer, seperate by comma
-classpath <local_file_list> classpaths used to run mainClass
-D <name>=<value> Property value pair, which will be used to run mainClass
-l Run job in local mode
举例如下:
jar -conf \home\admin\myconf -resources a.txt,example.jar -classpath ..\lib\example.jar:.\other_lib.jar -D java.library.path=.\native;
其中
<GENERIC_OPTIONS>
包括(均为可选参数):
- -conf <configuration file>:指定JobConf配置文件。
- -resources <resource_name_list>:MapReduce作业运行时使用的资源声明。一般情况下,resource_name_list中需要指定Map/Reduce函数所在的资源名称。
说明
如果您在Map/Reduce函数中读取了其他MaxCompute资源,则这些资源名称也需要被添加到resource_name_list中。
资源之间使用逗号分隔,使用跨项目空间使用资源时,需要前面加上
PROJECT/resources/
,例如:-resources otherproject/resources/resfile
。有关如何在Map/Reduce函数中读取资源的示例,请参见资源使用示例。
- -classpath <local_file_list>:本地执行时的classpath,主要用于指定main函数所在的Jar包的本地路径(包含相对路径和绝对路径)。
包名之间使用系统默认的文件分割符作分割。通常:Windows系统中使用分号(;);Linux系统中使用逗号(,)。如果您在云端服务器运行MR任务,则使用逗号(,)进行分隔。
说明 通常,您可能更习惯于将main函数与Map/Reduce函数编写在一个包中,例如:WordCount 代码示例。因此,在执行示例程序时,-resources及-classpath的参数中都出现了mapreduce-examples.jar。但二者意义不同:-resources引用的是Map/Reduce函数,运行于分布式环境中。而-classpath引用的是main函数,运行于本地,指定的Jar包路径也是本地文件路径。
- -D <prop_name>=<prop_value>:本地执行时,<mainClass>的Java属性,可以定义多个。
- -l:以本地模式执行MapReduce作业,主要用于程序调试。
您可以通过-conf选项指定JobConf配置文件,该文件可以影响SDK中JobConf的设置。
JobConf配置文件的示例如下:
<configuration>
<property>
<name>import.filename</name>
<value>resource.txt</value>
</property>
</configuration>
在上述示例中,通过JobConf配置文件定义一个名为import.filename的变量,该变量的值为resource.txt。
您可以在MapReduce程序中通过JobConf接口获取该变量的值。您通过SDK中JobConf接口可以达到相同的目的,详情请参见资源使用示例 。
示例如下:
add jar data\mapreduce-examples.jar;
jar -resources mapreduce-examples.jar -classpath data\mapreduce-examples.jar
org.alidata.odps.mr.examples.WordCount wc_in wc_out;
add file data\src.txt;
add jar data\mapreduce-examples.jar;
jar -resources src.txt,mapreduce-examples.jar -classpath data\mapreduce-examples.jar
org.alidata.odps.mr.examples.WordCount wc_in wc_out;
add file data\a.txt;
add table wc_in as test_table;
add jar data\work.jar;
jar -conf odps-mapred.xml -resources a.txt,test_table,work.jar
-classpath data\work.jar:otherlib.jar
-D import.filename=resource.txt org.alidata.odps.mr.examples.WordCount args;
原创文章,作者:网友投稿,如若转载,请注明出处:https://www.cloudads.cn/archives/33598.html