gpt4 book ai didi

hadoop - 使用 Mapreduce 为数据添加新列

转载 作者:可可西里 更新时间:2023-11-01 15:32:21 26 4
gpt4 key购买 nike

在处理数据时是否可以在 mapreduce 中追加列?示例:

我有 3 列的输入数据集 [EMPID,EMPNAME,EMP_DEPT],我想使用 mapreduce 处理这些数据。在减少阶段是否可以添加新列,比如 TIMESTAMP(处理记录时的系统时间戳)。 reducer 的输出应该是 EMPID,EMPNAME,EMP_DEPT,TIMESTAMP

输入数据:

EMPID EMPNAME EMP_DEPT
1 David HR
2 Sam IT

输出数据:

EMPID EMPNAME EMP_DEPT Timestamp
1 David HR XX:XX:XX:XX
2 Sam IT XX:XX:XX:XX

最佳答案

您的 MapReduce 的目的似乎只是添加时间戳“列”(关于您的输入和输出示例,没有对 EMPID、EMPNAME 和 EMP_DEPT 字段进行其他修改/转换/处理)。如果是这种情况,您唯一要做的就是将映射器中的时间戳添加到读取行(“行”);然后让 reducer 加入所有新的“行”。工作流程:

Each input file is splited into many chunks:
(input file) --> spliter --> split1, split2, ..., splitN

Each split content is:
split1 = {"1 David HR", "2 Sam IT"}
split2 = {...}

Splits are assigned to mappers (one per split), which output (key,value) pairs; in this case, it is enough with a common key for all the pairs:
(offset, "1 David HR") --> mapper1 --> ("key", "1 David HR 2015-06-13 12:23:45.242")
(offset, "2 Sam IT") --> mapper1 --> ("key", "2 Sam IT 2015-06-13 12:23:45.243")
...
"..." --> mapper2 --> ...
...

The reducer receives an array, for each different key, with all the pairs outputted by the mappers that have such a key:
("key", ["1 David HR 2015-06-13 12:23:45.242", "2 Sam IT 2015-06-13 12:23:45.243"]) --> reducer --> (output file)

如果您的目标是最终以某种方式处理原始数据,除了时间戳之外,还可以在映射器上进行。

关于hadoop - 使用 Mapreduce 为数据添加新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30801320/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com