178
英雄联盟
sort示例__示例程序_MapReduce_大数据计算服务-阿里云
(1)准备好测试程序jar包,假设名字为mapreduce-examples.jar;
(2)准备好sort的测试表和资源;
创建表
create table ss_in(key bigint, value bigint); create table ss_out(key bigint, value bigint);
添加资源
add jar mapreduce-examples.jar -f;
(3)使用tunnel导入数据;
tunnel upload data ss_in;
- 导入ss_in表的数据文件data内容为:
2,1
1,1
3,1
测试步骤
在odpscmd中执行Sort
jar -resources mapreduce-examples.jar -classpath mapreduce-examples.jar
com.aliyun.odps.mapred.open.example.Sort ss_in ss_out;
预期结果
作业成功结束。 输出表ss_out中内容为:
+------------+------------+
| key | value |
+------------+------------+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
+------------+------------+
代码示例
package com.aliyun.odps.mapred.open.example;
import java.io.IOException;
import java.util.Date;
import com.aliyun.odps.data.Record;
import com.aliyun.odps.data.TableInfo;
import com.aliyun.odps.mapred.JobClient;
import com.aliyun.odps.mapred.MapperBase;
import com.aliyun.odps.mapred.TaskContext;
import com.aliyun.odps.mapred.conf.JobConf;
import com.aliyun.odps.mapred.example.lib.IdentityReducer;
import com.aliyun.odps.mapred.utils.InputUtils;
import com.aliyun.odps.mapred.utils.OutputUtils;
import com.aliyun.odps.mapred.utils.SchemaUtils;
/**
* This is the trivial map/reduce program that does absolutely nothing other
* than use the framework to fragment and sort the input values.
*
**/
public class Sort {
static int printUsage() {
System.out.println("sort <input> <output>");
return -1;
}
/**
* Implements the identity function, mapping record's first two columns to
* outputs.
**/
public static class IdentityMapper extends MapperBase {
private Record key;
private Record value;
@Override
public void setup(TaskContext context) throws IOException {
key = context.createMapOutputKeyRecord();
value = context.createMapOutputValueRecord();
}
@Override
public void map(long recordNum, Record record, TaskContext context)
throws IOException {
key.set(new Object[] { (Long) record.get(0) });
value.set(new Object[] { (Long) record.get(1) });
context.write(key, value);
}
}
/**
* The main driver for sort program. Invoke this method to submit the
* map/reduce job.
*
* @throws IOException
* When there is communication problems with the job tracker.
**/
public static void main(String[] args) throws Exception {
JobConf jobConf = new JobConf();
jobConf.setMapperClass(IdentityMapper.class);
jobConf.setReducerClass(IdentityReducer.class);
jobConf.setNumReduceTasks(1);
jobConf.setMapOutputKeySchema(SchemaUtils.fromString("key:bigint"));
jobConf.setMapOutputValueSchema(SchemaUtils.fromString("value:bigint"));
InputUtils.addTable(TableInfo.builder().tableName(args[0]).build(), jobConf);
OutputUtils.addTable(TableInfo.builder().tableName(args[1]).build(), jobConf);
Date startTime = new Date();
System.out.println("Job started: " + startTime);
JobClient.runJob(jobConf);
Date end_time = new Date();
System.out.println("Job ended: " + end_time);
System.out.println("The job took "
+ (end_time.getTime() - startTime.getTime()) / 1000 + " seconds.");
}
}
最后更新:2016-11-24 11:23:47
上一篇:
unique示例__示例程序_MapReduce_大数据计算服务-阿里云
下一篇:
分区表输入示例__示例程序_MapReduce_大数据计算服务-阿里云
线性回归__示例程序_图模型_大数据计算服务-阿里云
LogShipper-状态__Getting-Started_日志服务-阿里云
云数据库Memcache版监控__云服务监控_用户指南_云监控-阿里云
ALIYUN::SLB::BackendServerAttachment__资源列表_资源编排-阿里云
概览页___用户指南_云监控-阿里云
子账号管理__账号管理_用户指南_企业级分布式应用服务 EDAS-阿里云
协议跟随回源__内容回源设置_用户指南_CDN-阿里云
云服务器 ECS Linux SSH 基于密钥交换的自动登录原理简介及配置说明__远程登录 (SSH)_Linux操作运维问题_云服务器 ECS-阿里云
统计项计算__SQL_日志分析平台_态势感知-阿里云
产品升级更新__用户指南_服务器安全(安骑士)-阿里云
相关内容
常见错误说明__附录_大数据计算服务-阿里云
发送短信接口__API使用手册_短信服务-阿里云
接口文档__Android_安全组件教程_移动安全-阿里云
运营商错误码(联通)__常见问题_短信服务-阿里云
设置短信模板__使用手册_短信服务-阿里云
OSS 权限问题及排查__常见错误及排除_最佳实践_对象存储 OSS-阿里云
消息通知__操作指南_批量计算-阿里云
设备端快速接入(MQTT)__快速开始_阿里云物联网套件-阿里云
查询API调用流量数据__API管理相关接口_API_API 网关-阿里云
使用STS访问__JavaScript-SDK_SDK 参考_对象存储 OSS-阿里云