如何使用 mapreduce 从具有 RCFile 存储格式的 HDFS 解析 Map<string,string>?

Posted

技术标签:

【中文标题】如何使用 mapreduce 从具有 RCFile 存储格式的 HDFS 解析 Map<string,string>?【英文标题】:How to parse Map<string,string> from HDFS with RCFile storage format using mapreduce? 【发布时间】:2019-05-31 00:07:53 【问题描述】:

在 hive 中,有一列类型为 Map&lt;string,string&gt;。我想使用 mapreduce 从 hdfs 解析地图的键值信息。功能图如下:

void map(LongWritable key, BytesRefArrayWritable value, Context context) 
    Text text = new Text();
    // this is the map column
    BytesRefWritable m  = value.get(1);
    text.set(m.getData(), m.getStart(), m.getLength())
    context.write(text, NullWritable.get())

然后我从输出文件中读取,发现key-value解析如下: key1:value1key2:value2... 我无法在没有任何分隔符的情况下解析键值对。 那么,如何从 hdfs 解析 Map&lt;string,string&gt; 呢?

【问题讨论】:

【参考方案1】:

好的,我会自己回答这个问题。

在 hdfs 中,Map 中的键值对或 Array 中的元素由 \002 分隔。键和值的分隔符是\003。据此,我们可以解析hdfs中的所有元素。

【讨论】:

以上是关于如何使用 mapreduce 从具有 RCFile 存储格式的 HDFS 解析 Map<string,string>?的主要内容,如果未能解决你的问题,请参考以下文章

具有多种键类型的 Hadoop MapReduce 映射器和化简器

具有最少磁盘操作的大数据 - MapReduce

无法从 MapReduce 代码访问 HBase

在 MapReduce 中调用多个具有不同 InputFormatClass 的 Mapper

HDFS 文件格式——SequenceFile RCFile

如何从 mapreduce 中引用本地 hdfs 文件?