hadoop - Map Reduce 输出到 CSV 还是我需要键值?

标签 hadoop mapreduce hadoop-streaming elastic-map-reduce

我的 map 函数产生一个

键\t值

值 = 列表(值 1、值 2、值 3)

然后我的 reduce 函数产生:

Key\tCSV-Line

例如


2323232-2322 fdsfs,sdfs,dfsfs,0,0,0,2,fsda,3,23,3,s,

2323555-22222 dfasd,sdfas,adfs,0,0,2,0,fasafa,2,23,s


例。原始数据: 232342|@3423@|34343|sfasdfasdF|433443|Sfasfdas|324343 x 1000

无论如何,我想删除开头的 key ,这样我的客户就可以直接导入到 mysql 中。我有大约 50 个数据文件,我的问题是在它映射一次并且 reducer 启动后它需要打印出带有值的键还是我可以只打印值吗?


更多信息:

这段代码可能会更好地说明情况

http://pastebin.ca/2410217

这有点像我打算做的。

最佳答案

如果您不想发出 key ,请在您的代码中将其设置为 NullWritable。例如:

public static class TokenCounterReducer extends
            Reducer<Text, IntWritable, NullWritable, IntWritable> {
        public void reduce(Text key, Iterable<IntWritable> values,
                Context context) throws IOException, InterruptedException {
            int sum = 0;
            for (IntWritable value : values) {
                sum += value.get();
            }
            context.write(NullWritable.get(), new IntWritable(sum));
//          context.write(key, new IntWritable(sum));
        }

如果这不是您需要的,请告诉我,我会相应地更新答案。

关于hadoop - Map Reduce 输出到 CSV 还是我需要键值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17332202/

相关文章:

hadoop - HBase聚合、Get And Put操作、Bulk操作

hadoop - 如何读取 Hadoop Sequentil 文件作为 Hadoop 作业的输入?

hadoop - 如何在具有单节点(CentOS)Yarn 集群的单机(CentOS)上安装 spark

hadoop - 了解 mapper 和 reducer 的用法

eclipse - 在 Eclipse 中运行 Map Reduce 程序

java - Hadoop Java 错误 : Exception in thread "main" java. lang.ClassNotFoundException : com. packt.ch3.etl.ParseWeblogs

mysql - 在配置单元中创建数据库失败

hadoop - 是否可以在 sqoop 类型映射中指定 DECIMAL 比例和精度?

r - Hadoop 流在 R 中失败

python - 使用带有子进程、管道、Popen 的 python 从 hdfs 读取/写入文件给出错误