HBASE-3811 Allow adding attributes to Scan
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1127676 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
81aae08c4a
commit
d3045093c7
|
@ -228,6 +228,7 @@ Release 0.91.0 - Unreleased
|
|||
HBASE-3880 Make mapper function in ImportTSV plug-able (Bill Graham)
|
||||
HBASE-2938 HBASE-2938 Add Thread-Local Behavior To HTable Pool
|
||||
(Karthick Sankarachary)
|
||||
HBASE-3811 Allow adding attributes to Scan (Alex Baranau)
|
||||
|
||||
TASKS
|
||||
HBASE-3559 Move report of split to master OFF the heartbeat channel
|
||||
|
|
|
@ -29,10 +29,13 @@ import org.apache.hadoop.hbase.io.TimeRange;
|
|||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.io.Writable;
|
||||
import org.apache.hadoop.io.WritableFactories;
|
||||
import org.apache.hadoop.io.WritableUtils;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.TreeMap;
|
||||
|
@ -79,11 +82,13 @@ import java.util.TreeSet;
|
|||
* execute {@link #setCacheBlocks(boolean)}.
|
||||
*/
|
||||
public class Scan implements Writable {
|
||||
private static final byte SCAN_VERSION = (byte)1;
|
||||
private static final byte SCAN_VERSION = (byte)2;
|
||||
private byte [] startRow = HConstants.EMPTY_START_ROW;
|
||||
private byte [] stopRow = HConstants.EMPTY_END_ROW;
|
||||
private int maxVersions = 1;
|
||||
private int batch = -1;
|
||||
private Map<String, byte[]> attributes;
|
||||
|
||||
/*
|
||||
* -1 means no caching
|
||||
*/
|
||||
|
@ -439,6 +444,55 @@ public class Scan implements Writable {
|
|||
return cacheBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets arbitrary scan's attribute.
|
||||
* In case value = null attribute is removed from the attributes map.
|
||||
* @param name attribute name
|
||||
* @param value attribute value
|
||||
*/
|
||||
public void setAttribute(String name, byte[] value) {
|
||||
if (attributes == null && value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attributes == null) {
|
||||
attributes = new HashMap<String, byte[]>();
|
||||
}
|
||||
|
||||
if (value == null) {
|
||||
attributes.remove(name);
|
||||
if (attributes.isEmpty()) {
|
||||
this.attributes = null;
|
||||
}
|
||||
} else {
|
||||
attributes.put(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets scan's attribute
|
||||
* @param name attribute name
|
||||
* @return attribute value if attribute is set, <tt>null</tt> otherwise
|
||||
*/
|
||||
public byte[] getAttribute(String name) {
|
||||
if (attributes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return attributes.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all scan's attributes
|
||||
* @return unmodifiable map of all attributes
|
||||
*/
|
||||
public Map<String, byte[]> getAttributesMap() {
|
||||
if (attributes == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return Collections.unmodifiableMap(attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
|
@ -539,6 +593,18 @@ public class Scan implements Writable {
|
|||
}
|
||||
this.familyMap.put(family, set);
|
||||
}
|
||||
|
||||
if (version > 1) {
|
||||
int numAttributes = in.readInt();
|
||||
if (numAttributes > 0) {
|
||||
this.attributes = new HashMap<String, byte[]>();
|
||||
for(int i=0; i<numAttributes; i++) {
|
||||
String name = WritableUtils.readString(in);
|
||||
byte[] value = Bytes.readByteArray(in);
|
||||
this.attributes.put(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(final DataOutput out)
|
||||
|
@ -571,6 +637,16 @@ public class Scan implements Writable {
|
|||
out.writeInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.attributes == null) {
|
||||
out.writeInt(0);
|
||||
} else {
|
||||
out.writeInt(this.attributes.size());
|
||||
for (Map.Entry<String, byte[]> attr : this.attributes.entrySet()) {
|
||||
WritableUtils.writeString(out, attr.getKey());
|
||||
Bytes.writeByteArray(out, attr.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue