【问题标题】:What determines how many times map() will get called?什么决定了 map() 将被调用多少次?
【发布时间】:2015-03-17 23:34:36
【问题描述】:

我有一个文本文件和一个解析器,它将解析每一行并存储到我的 customSplitInput 中,我在我的自定义 FileInputFormat 阶段进行解析,所以我的拆分是自定义的。现在,我有 2 个拆分,每个拆分中都包含我的数据列表。

但是现在,我的映射器函数在同一个拆分中被重复调用。我认为 mapper 函数只会根据您拥有的拆分数量被调用?

我不知道这是否适用,但我的自定义 InputSplit 为 getLength() 返回一个固定数字,为 getLocation() 返回一个空字符串数组。我不确定要为这些添加什么。

@Override
    public RecordReader<LongWritable, ArrayWritable> createRecordReader(
            InputSplit input, TaskAttemptContext taskContext)
            throws IOException, InterruptedException {
        logger.info(">>> Creating Record Reader");
        CustomRecordReader recordReader = new CustomRecordReader(
                (EntryInputSplit) input);
        return recordReader;
    }

【问题讨论】:

    标签: hadoop mapreduce hadoop-yarn


    【解决方案1】:

    map() 为您的InputFormat 中的RecordReader 中的每条记录调用一次(或被您的InputFormat 引用)。例如,TextInputFormat 为输入中的每一行调用 map(),即使拆分中通常有很多行。

    【讨论】:

    • 我添加了我的记录阅读器创建功能。它只是使用我的自定义拆分创建一个记录阅读器并返回
    • 好的。我的回答能回答你的问题吗?
    • 抱歉,您的回答对我的代码没有意义。我的 createRecordReader 只返回一个包含 25 个项目列表的 1 个拆分的 recordReader。但是 mapper 函数被调用了超过 25 次。我的 CustomInputFormat 只创建了 2 个拆分,因此,同样,每个 recordReader 将有 1 个拆分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-20
    • 2011-04-27
    • 2013-11-20
    • 2019-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多