我通过扩展WritableByteArrayComparable
类以比较HBase中的长度来编写自定义比较器。这是供参考的代码。
import org.apache.hadoop.hbase.filter.WritableByteArrayComparable;
import org.apache.hadoop.hbase.util.Bytes;
public class LongWritableComparable extends WritableByteArrayComparable {
public LongWritableComparable() {
super();
}
public LongWritableComparable(byte[] value) {
super(value);
}
public LongWritableComparable(Long value) {
super(Bytes.toBytes(value));
}
@Override
public int compareTo(byte[] otherValue, int arg1, int arg2) {
// TODO Auto-generated method stub
byte[] thisValue = this.getValue();
long thisLong = Bytes.toLong(thisValue);
long otherLong = Bytes.toLong(otherValue,arg1,arg2);
if (thisLong == otherLong) {
return 0;
}
if (thisLong < otherLong) {
return -1;
}
return 1;
}
}
我在驱动程序类中使用了类似的比较器:
long endtimelongval = Long.valueOf(datetime.get("endDate").getMillis()).longValue();
LongWritableComparable etval=new LongWritableComparable(endtimelongval);
SingleColumnValueFilter eventCreationEndTimeFilter = new SingleColumnValueFilter(Bytes.toBytes("d"), Bytes.toBytes("et"), CompareOp.LESS,etval );
当我执行上述代码时,它会以错误:
进行。Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.hbase.filter.SingleColumnValueFilter.<init>([B[BLorg/apache/hadoop/hbase/filter/CompareFilter$CompareOp;Lorg/apache/hadoop/hbase/filter/WritableByteArrayComparable;)V
在SingleColumnValueFilter
行中。
任何人都帮助我解决了您的解决方案。预先感谢。
我找到了一种方法,无需编写自定义比较器。getmillis()将在毫里返回几秒钟,但是在我们的HBase表中,我们在几秒钟内具有EPOC值,因此我更改为以下,并且可以正常工作。
long startlongval = long.valueof(dateTime.get(" startDate")。getmillis())。longValue()/1000L;
SingleColumnValueFilter EventCreationStartTimeFilter = new SinglecolumnValueFilter(bytes.tobytes(" d"),bytes.tobytes(" et"),compareop.greater.greater,bytes.tobytes(startlongval);