178
iPhone_iPad_Mac_手機_平板_蘋果apple
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-阿裏雲