- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
compare()
和 compareTo()
如果我们谈论排序键,它们是同义的但我只想知道在高度配置机器的时代是否需要考虑关于何时使用 compare()
以及何时使用 compareTo()
?
如果需要考虑 compare(byte b1[],int s1,int l1, byte b2[],int s2,int l2)
比 compareTo(object key1,Object key2)
然后请建议我们真正需要决定使用哪一个的字段或用例或问题类型?
谢谢你!!
最佳答案
RawComparator的使用:
如果您仍然想优化 Map Reduce Job 所花费的时间,那么您必须使用 RawComparator。
中间键值对已经从 Mapper 传递到 Reducer。在这些值从 Mapper 到达 Reducer 之前,将执行洗牌和排序步骤。
排序得到改进,因为 RawComparator 将按字节比较键。如果我们不使用 RawComparator,则必须完全反序列化中间键才能执行比较。
示例:
public class IndexPairComparator extends WritableComparator {
protected IndexPairComparator() {
super(IndexPair.class);
}
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
int i1 = readInt(b1, s1);
int i2 = readInt(b2, s2);
int comp = (i1 < i2) ? -1 : (i1 == i2) ? 0 : 1;
if(0 != comp)
return comp;
int j1 = readInt(b1, s1+4);
int j2 = readInt(b2, s2+4);
comp = (j1 < j2) ? -1 : (j1 == j2) ? 0 : 1;
return comp;
}
在上面的例子中,我们没有直接实现 RawComparator。相反,我们扩展了 WritableComparator,它在内部实现了 RawComparator。
看看这个article作者:Jee Vang
WritableComparator 中 RawComparator() 的实现:只比较键值
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
try {
buffer.reset(b1, s1, l1); // parse key1
key1.readFields(buffer);
buffer.reset(b2, s2, l2); // parse key2
key2.readFields(buffer);
} catch (IOException e) {
throw new RuntimeException(e);
}
return compare(key1, key2); // compare them
}
看看source
关于java - 原始比较器与 WritableComparable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33367872/
刚开始探索mapreduce,遇到了有compareTo()方法的Writablecomparable接口(interface)和有compare()方法的Writablecomparator,当我们
compare() 和 compareTo() 如果我们谈论排序键,它们是同义的但我只想知道在高度配置机器的时代是否需要考虑关于何时使用 compare() 以及何时使用 compareTo()? 如
下面是我使用 WritableComparator 的代码片段,但它不起作用 import org.apache.hadoop.io.WritableComparable;import org.apa
我正在尝试实现自定义 WritableComparable,如图所示 In this link 当我尝试在我的映射器方法中初始化自定义可写比较类时出现错误。我已经在我的代码中显示了我的错误。textp
我是 Hadoop 和 Java 的新手,我觉得我缺少一些明显的东西。如果这意味着什么,我正在使用 Hadoop 1.0.3。 我使用 hadoop 的目标是获取一堆文件并一次解析一个文件(而不是逐行
我需要在 Job 中使用 setGroupingComparatorClass 方法,它需要一个类型为 WritableComparable 的参数。 我无法实现 WritableComparable
尝试使用 Maven(或使用我的 IDE IntelliJ)编译我的 Pig UDF 时出现以下错误: cannot access org.apache.hadoop.io.WritableCompa
我已经为我的 map 作业实现了 WritableComparable 并向它传递了三个值。 public class KeyCustom implementsw WritableComparable
谁能给我解释一下: 什么是Hadoop中的Writable和Writable Comparable接口(interface)? 这两者有什么区别? 请举例说明。 提前致谢 最佳答案 Writable
您能否解释一下Java中的RAW Type是什么,我可以在Internet上找到更有意义的东西。 例如: Hadoop WritableComparable RawType , 什么是 RawType
我一直在尝试运行 hadoop 0.20.205.0 MapReduce 作业(单线程,本地),它表现出各种奇怪和意外的行为。我终于明白为什么了。在我看来,这就像是 hadoop 中的一个错误,但也许
在输出从 mapper 传递到 reducer 之前,mapreduce 中如何进行排序。如果我的映射器输出键是 IntWritable 类型,它是否使用 IntWritable 类中定义的比较器或类
我是一名优秀的程序员,十分优秀!