NewInstallUserReducer.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:big_data 作者:
@Override
protected void reduce(StatsUserDimension key, Iterable<TimeOutputValue> values, Context context)
        throws IOException, InterruptedException {
    this.unique.clear();

    // 开始计算uuid的个数
    for (TimeOutputValue value : values) {
        this.unique.add(value.getId());// uid,用户ID
    }
    MapWritable map = new MapWritable();// 相当于java中的hashmap
    map.put(new IntWritable(-1), new IntWritable(this.unique.size()));
    outputValue.setValue(map);

    // 设置kpi名称
    String kpiName = key.getStatsCommon().getKpi().getKpiName();
    if (KpiType.NEW_INSTALL_USER.name.equals(kpiName)) {
        // 计算stats_user表中的新增用户
        outputValue.setKpi(KpiType.NEW_INSTALL_USER);
    } else if (KpiType.BROWSER_NEW_INSTALL_USER.name.equals(kpiName)) {
        // 计算stats_device_browser表中的新增用户
        outputValue.setKpi(KpiType.BROWSER_NEW_INSTALL_USER);
    }
    context.write(key, outputValue);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号