@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { tuple.getKey(ptr); int offset = accessor.getOffset(ptr.get(), ptr.getOffset()); // Null is represented in the last expression of a multi-part key // by the bytes not being present. if (offset < ptr.getOffset() + ptr.getLength()) { byte[] buffer = ptr.get(); int maxByteSize = ptr.getLength() - (offset - ptr.getOffset()); int fixedByteSize = -1; // FIXME: fixedByteSize <= maxByteSize ? fixedByteSize : 0 required because HBase passes bogus // keys to filter to position scan (HBASE-6562) if (fromType.isFixedWidth()) { fixedByteSize = getByteSize(); fixedByteSize = fixedByteSize <= maxByteSize ? fixedByteSize : 0; } int length = fixedByteSize >= 0 ? fixedByteSize : accessor.getLength(buffer, offset, maxByteSize); // In the middle of the key, an empty variable length byte array represents null if (length > 0) { if (type == fromType) { ptr.set(buffer, offset, length); } else { ptr.set(type.toBytes(type.toObject(buffer, offset, length, fromType))); } return true; } } return false; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((accessor == null) ? 0 : accessor.hashCode()); return result; }
@Override public void readFields(DataInput input) throws IOException { super.readFields(input); accessor = new RowKeyValueAccessor(); accessor.readFields(input); fromType = type; // fromType only needed on client side }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; RowKeyColumnExpression other = (RowKeyColumnExpression) obj; return accessor.equals(other.accessor); }
@Override public String toString() { return name == null ? "PK[" + accessor.getIndex() + "]" : name; }
public int getPosition() { return accessor.getIndex(); }
@Override public void write(DataOutput output) throws IOException { super.write(output); accessor.write(output); }