我的Map器将向reducer发出<text,text>,键实际上是double,例如,<'34.90','hello'>,表示“hello”的平均计数是34.90。另外,输入格式为:hello 34.90 1:10;小说2:20;。。。,看来我不能用倒计时器了。
我尝试使用'doublewritable'作为键,但我不知道如何发出它,collect似乎只发出<text,text>。
问题是,929.00比93.00小,这是事实,所以我想定义一个新的text.comparator,我看到了源代码
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)
{
int n1 = WritableUtils.decodeVIntSize(b1[s1]);
int n2 = WritableUtils.decodeVIntSize(b2[s2]);
return compareBytes(b1, s1 + n1, l1 - n1, b2, s2 + n2, l2 - n2);
}
我不明白 s1+n1
以及 l1-n1
意思。
谢谢你的帮助。
1条答案
按热度按时间vshtjzan1#
你可以用
FloatWritable
. 下面是如何在mapper中发射它。您不需要在这里定义一个定制的comparator类,floatwriteable的内置功能将解决这个问题。