关于reduce输出write方法

关于hadoop一些自定义输出
code>OutputFormat</code> describes the output-specification for a 
 * Map-Reduce job.
首先继承outputFormat<key,value>这个抽象类 Map-Reduce job的输出规范
实现他的方法:
RecordWriter<KeyBaseDimension, BaseStatsValueWritable> getRecordWriter 在方法内可以进行数据库连接操作
这里需要一个返回一个RecordWriter 
继承这个RecordWriter类
 实现里面的write方法 进行数据库jdbc存储即可
 
 
 关于reduce端输出时会调用的write方法
 实现类为:TaskInputOutputContextImpl
  private RecordWriter<KEYOUT,VALUEOUT> output;
  public void write(KEYOUT key, VALUEOUT value
                    ) throws IOException, InterruptedException {
    output.write(key, value);
  }
  最终是调用了RecordWriter的write方法,


map端读取hbase一个mr工具类
*在提交TableMap作业之前使用此选项。它将被适当地设置
*工作。
TableMapReduceUtil 这个类很重要,在提交读取hbase表job之前可以对其进行一系列过滤操作
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);

        filterList.addFilter(
                new SingleColumnValueFilter(EventLogConstants.EVENT_LOGS_FAMILY_NAME_BYTES,
                        Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME),
                        CompareOp.EQUAL, Bytes.toBytes(EventLogConstants.EventEnum.BC_SX.alias)));
 
   
public static void initTableMapperJob(List<Scan> scans,
      Class<? extends TableMapper> mapper,
      Class<?> outputKeyClass,
      Class<?> outputValueClass, Job job,
      boolean addDependencyJars,
      boolean initCredentials) throws IOException {
 scan之前进行过滤器数据
List<Scan> scanList = new ArrayList<Scan>(); try { conn = ConnectionFactory.createConnection(conf); admin = conn.getAdmin(); String tableName = EventLogConstants.HBASE_NAME_AUDIT_SX + GlobalConstants.UNDERLINE + statDate.replaceAll(GlobalConstants.KEY_SEPARATOR, ""); if (admin.tableExists(TableName.valueOf(tableName))) { Scan scan = new Scan();

scan读取多个表的设置
// If an application wants to use multiple scans over different tables each scan must // define this attribute with the appropriate table name by calling // scan.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, Bytes.toBytes(tableName)) // static public final String SCAN_ATTRIBUTES_TABLE_NAME = "scan.attributes.table.name"; scan.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, Bytes.toBytes(tableName)); scan.setFilter(filterList); scanList.add(scan);
}
最后将job 与scanlist都设置进去

TableMapReduceUtil.initTableMapperJob(scanList, AuditorSXMapper.class,

AuditorDimensionKey.class, Text.class, job, false);

 

 

 
  
strom一些笔记知识

 storm echo(File(),fun,File())
 filter:实现filter接口 iskeep方法
 partitionAggregate函数:分区内聚合,实现aggregate<保存聚合状态的类> 的aggregate实现聚合逻辑 ,complete方法 ridentCollector collector.emit(Value(聚合后的值))
 一般的key拼接函数:实现function接口的execute方法
 HBaseMapState.Options optsWait = new HBaseMapState.Options();
 
     TridentState amtOfWaitState = partStream.project(new Fields("waitingTotalOfPartDay","dayAndContType"))
                .groupBy(new Fields("dayAndContType"))
                .persistentAggregate(
                        factoryWait,
                        new Fields("waitingTotalOfPartDay"),new Sum(),
                        new Fields("waitingGlobalOfDay")
                );
 
 persistentAggregate 持久化保存函数 进行全区的sum求和,输入各区,输出为总和
 
  

 

 

 

转载于:https://www.cnblogs.com/hejunhong/p/10423281.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值