hadoop 2.4.0使用TAB作为分隔符的流通用解析器选项

ann*_*ist 7 python hadoop mapreduce utf-8 hadoop-streaming

我知道该选项卡是字段的默认输入分隔符:

stream.map.output.field.separator
stream.reduce.input.field.separator
stream.reduce.output.field.separator
mapreduce.textoutputformat.separator
Run Code Online (Sandbox Code Playgroud)

但如果我尝试编写通用解析器选项:

stream.map.output.field.separator=\t (or)  
stream.map.output.field.separator="\t"
Run Code Online (Sandbox Code Playgroud)

测试hadoop如何在用作分隔符时解析像"\ t,\n,\ f"这样的空格字符.我观察到hadoop将其视为\ t字符而不是" " tab space itself. I checked it by printing each line in reducer (python) as it reads using :

sys.stdout.write(str(line))
Run Code Online (Sandbox Code Playgroud)

My mapper emits key/value pairs as : key value1 value2

使用print (key,value1,value2,sep='\t',end='\n')命令.

所以我希望我的减速器读取每一行:key value1 value2也是,但是sys.stdout.write(str(line))打印:

key value1 value2 \\with trailing space

Hadoop流 - 从reducer输出中删除尾随选项卡,我理解尾随空间是由于mapreduce.textoutputformat.separator未设置并保留为默认值.

所以,这证实了我的假设,即hadoop考虑了我的总地图输出:

key value1 value2

作为空文本对象的键和值,因为它从stream.map.output.field.separator=\t"\ t"字符而不是" "制表符空间本身读取分隔符.

请帮助我理解这种行为,如果我愿意,如何使用\ t作为分隔符.

Ram*_*mzy 1

您可能会遇到此问题“-Dstream.map.output.field.separator=”。指定“.” 作为映射输出的字段分隔符,以及直到第四个“.”的前缀。一行中的内容将是键,该行的其余部分(不包括第四个“.”)将是值。如果一行中的“.”少于四个,则整行将是键,值将是一个空的 Text 对象(如 new Text("") 创建的对象)。 这里清楚地提到了分隔符是如何使用的,以及在识别映射键和值时需要考虑多少次此类分隔符的出现。还有一些与分区相关的字段,reducer 将根据这些字段进行处理。当您希望更改分隔符时,我认为您必须验证这也与分区和减速器有关。