HBASE-17249 Get/Scan's setTimeRange/setColumnFamilyTimeRange can take the TimeRange reference as the parameter instead of creating a new setColumnFamilyTimeRange instance. (huaxiang sun)
This commit is contained in:
parent
1eb24e4e8e
commit
61220e4d7c
|
@ -74,7 +74,6 @@ public class Get extends Query
|
||||||
private boolean cacheBlocks = true;
|
private boolean cacheBlocks = true;
|
||||||
private int storeLimit = -1;
|
private int storeLimit = -1;
|
||||||
private int storeOffset = 0;
|
private int storeOffset = 0;
|
||||||
private TimeRange tr = new TimeRange();
|
|
||||||
private boolean checkExistenceOnly = false;
|
private boolean checkExistenceOnly = false;
|
||||||
private boolean closestRowBefore = false;
|
private boolean closestRowBefore = false;
|
||||||
private Map<byte [], NavigableSet<byte []>> familyMap =
|
private Map<byte [], NavigableSet<byte []>> familyMap =
|
||||||
|
@ -203,9 +202,19 @@ public class Get extends Query
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @return this for invocation chaining
|
* @return this for invocation chaining
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Get setTimeRange(long minStamp, long maxStamp) throws IOException {
|
public Get setTimeRange(long minStamp, long maxStamp) throws IOException {
|
||||||
tr = new TimeRange(minStamp, maxStamp);
|
return (Get) super.setTimeRange(minStamp, maxStamp);
|
||||||
return this;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get versions of columns only within the specified timestamp range,
|
||||||
|
* @param tr Input TimeRange
|
||||||
|
* @return this for invocation chaining
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Get setTimeRange(TimeRange tr) {
|
||||||
|
return (Get) super.setTimeRange(tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,7 +225,7 @@ public class Get extends Query
|
||||||
public Get setTimeStamp(long timestamp)
|
public Get setTimeStamp(long timestamp)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try {
|
try {
|
||||||
tr = new TimeRange(timestamp, timestamp+1);
|
super.setTimeRange(timestamp, timestamp + 1);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
// This should never happen, unless integer overflow or something extremely wrong...
|
// This should never happen, unless integer overflow or something extremely wrong...
|
||||||
LOG.error("TimeRange failed, likely caused by integer overflow. ", e);
|
LOG.error("TimeRange failed, likely caused by integer overflow. ", e);
|
||||||
|
@ -225,10 +234,16 @@ public class Get extends Query
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Get setColumnFamilyTimeRange(byte[] cf, long minStamp, long maxStamp) {
|
@Override
|
||||||
|
public Get setColumnFamilyTimeRange(byte[] cf, long minStamp, long maxStamp) {
|
||||||
return (Get) super.setColumnFamilyTimeRange(cf, minStamp, maxStamp);
|
return (Get) super.setColumnFamilyTimeRange(cf, minStamp, maxStamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Get setColumnFamilyTimeRange(byte[] cf, TimeRange tr) {
|
||||||
|
return (Get) super.setColumnFamilyTimeRange(cf, tr);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all available versions.
|
* Get all available versions.
|
||||||
* @return this for invocation chaining
|
* @return this for invocation chaining
|
||||||
|
@ -344,14 +359,6 @@ public class Get extends Query
|
||||||
return this.storeOffset;
|
return this.storeOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Method for retrieving the get's TimeRange
|
|
||||||
* @return timeRange
|
|
||||||
*/
|
|
||||||
public TimeRange getTimeRange() {
|
|
||||||
return this.tr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for retrieving the keys in the familyMap
|
* Method for retrieving the keys in the familyMap
|
||||||
* @return keys in the current familyMap
|
* @return keys in the current familyMap
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.client;
|
package org.apache.hadoop.hbase.client;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
@ -45,6 +46,7 @@ public abstract class Query extends OperationWithAttributes {
|
||||||
protected Consistency consistency = Consistency.STRONG;
|
protected Consistency consistency = Consistency.STRONG;
|
||||||
protected Map<byte[], TimeRange> colFamTimeRangeMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
|
protected Map<byte[], TimeRange> colFamTimeRangeMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
|
||||||
protected Boolean loadColumnFamiliesOnDemand = null;
|
protected Boolean loadColumnFamiliesOnDemand = null;
|
||||||
|
protected TimeRange tr = new TimeRange();
|
||||||
/**
|
/**
|
||||||
* @return Filter
|
* @return Filter
|
||||||
*/
|
*/
|
||||||
|
@ -64,6 +66,36 @@ public abstract class Query extends OperationWithAttributes {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TimeRange
|
||||||
|
*/
|
||||||
|
public TimeRange getTimeRange() {
|
||||||
|
return tr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the TimeRange to be used by this Query
|
||||||
|
* @param tr TimeRange
|
||||||
|
* @return Query
|
||||||
|
*/
|
||||||
|
public Query setTimeRange(TimeRange tr) {
|
||||||
|
this.tr = tr;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the TimeRange to be used by this Query
|
||||||
|
* [minStamp, maxStamp).
|
||||||
|
* @param minStamp minimum timestamp value, inclusive
|
||||||
|
* @param maxStamp maximum timestamp value, exclusive
|
||||||
|
* @throws IOException
|
||||||
|
* @return this for invocation chaining
|
||||||
|
*/
|
||||||
|
public Query setTimeRange(long minStamp, long maxStamp) throws IOException {
|
||||||
|
tr = new TimeRange(minStamp, maxStamp);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the authorizations to be used by this Query
|
* Sets the authorizations to be used by this Query
|
||||||
* @param authorizations
|
* @param authorizations
|
||||||
|
@ -227,12 +259,16 @@ public abstract class Query extends OperationWithAttributes {
|
||||||
* @param maxStamp maximum timestamp value, exclusive
|
* @param maxStamp maximum timestamp value, exclusive
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Query setColumnFamilyTimeRange(byte[] cf, long minStamp, long maxStamp) {
|
public Query setColumnFamilyTimeRange(byte[] cf, long minStamp, long maxStamp) {
|
||||||
colFamTimeRangeMap.put(cf, new TimeRange(minStamp, maxStamp));
|
colFamTimeRangeMap.put(cf, new TimeRange(minStamp, maxStamp));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Query setColumnFamilyTimeRange(byte[] cf, TimeRange tr) {
|
||||||
|
colFamTimeRangeMap.put(cf, tr);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A map of column families to time ranges
|
* @return A map of column families to time ranges
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -135,7 +135,6 @@ public class Scan extends Query {
|
||||||
private long maxResultSize = -1;
|
private long maxResultSize = -1;
|
||||||
private boolean cacheBlocks = true;
|
private boolean cacheBlocks = true;
|
||||||
private boolean reversed = false;
|
private boolean reversed = false;
|
||||||
private TimeRange tr = new TimeRange();
|
|
||||||
private Map<byte [], NavigableSet<byte []>> familyMap =
|
private Map<byte [], NavigableSet<byte []>> familyMap =
|
||||||
new TreeMap<byte [], NavigableSet<byte []>>(Bytes.BYTES_COMPARATOR);
|
new TreeMap<byte [], NavigableSet<byte []>>(Bytes.BYTES_COMPARATOR);
|
||||||
private Boolean asyncPrefetch = null;
|
private Boolean asyncPrefetch = null;
|
||||||
|
@ -325,7 +324,7 @@ public class Scan extends Query {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get versions of columns only within the specified timestamp range,
|
* Set versions of columns only within the specified timestamp range,
|
||||||
* [minStamp, maxStamp). Note, default maximum versions to return is 1. If
|
* [minStamp, maxStamp). Note, default maximum versions to return is 1. If
|
||||||
* your time range spans more than one version and you want all versions
|
* your time range spans more than one version and you want all versions
|
||||||
* returned, up the number of versions beyond the default.
|
* returned, up the number of versions beyond the default.
|
||||||
|
@ -335,9 +334,18 @@ public class Scan extends Query {
|
||||||
* @see #setMaxVersions(int)
|
* @see #setMaxVersions(int)
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Scan setTimeRange(long minStamp, long maxStamp) throws IOException {
|
public Scan setTimeRange(long minStamp, long maxStamp) throws IOException {
|
||||||
tr = new TimeRange(minStamp, maxStamp);
|
return (Scan) super.setTimeRange(minStamp, maxStamp);
|
||||||
return this;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set versions of columns only within the specified timestamp range,
|
||||||
|
* @param tr Input TimeRange
|
||||||
|
* @return this for invocation chaining
|
||||||
|
*/
|
||||||
|
public Scan setTimeRange(TimeRange tr) {
|
||||||
|
return (Scan) super.setTimeRange(tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -353,7 +361,7 @@ public class Scan extends Query {
|
||||||
public Scan setTimeStamp(long timestamp)
|
public Scan setTimeStamp(long timestamp)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try {
|
try {
|
||||||
tr = new TimeRange(timestamp, timestamp+1);
|
super.setTimeRange(timestamp, timestamp + 1);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
// This should never happen, unless integer overflow or something extremely wrong...
|
// This should never happen, unless integer overflow or something extremely wrong...
|
||||||
LOG.error("TimeRange failed, likely caused by integer overflow. ", e);
|
LOG.error("TimeRange failed, likely caused by integer overflow. ", e);
|
||||||
|
@ -362,10 +370,16 @@ public class Scan extends Query {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Scan setColumnFamilyTimeRange(byte[] cf, long minStamp, long maxStamp) {
|
@Override
|
||||||
|
public Scan setColumnFamilyTimeRange(byte[] cf, long minStamp, long maxStamp) {
|
||||||
return (Scan) super.setColumnFamilyTimeRange(cf, minStamp, maxStamp);
|
return (Scan) super.setColumnFamilyTimeRange(cf, minStamp, maxStamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Scan setColumnFamilyTimeRange(byte[] cf, TimeRange tr) {
|
||||||
|
return (Scan) super.setColumnFamilyTimeRange(cf, tr);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the start row of the scan.
|
* Set the start row of the scan.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -665,13 +679,6 @@ public class Scan extends Query {
|
||||||
return this.caching;
|
return this.caching;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return TimeRange
|
|
||||||
*/
|
|
||||||
public TimeRange getTimeRange() {
|
|
||||||
return this.tr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return RowFilter
|
* @return RowFilter
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -385,13 +385,12 @@ public final class ProtobufUtil {
|
||||||
if (proto.getCfTimeRangeCount() > 0) {
|
if (proto.getCfTimeRangeCount() > 0) {
|
||||||
for (HBaseProtos.ColumnFamilyTimeRange cftr : proto.getCfTimeRangeList()) {
|
for (HBaseProtos.ColumnFamilyTimeRange cftr : proto.getCfTimeRangeList()) {
|
||||||
TimeRange timeRange = protoToTimeRange(cftr.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(cftr.getTimeRange());
|
||||||
get.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(),
|
get.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(), timeRange);
|
||||||
timeRange.getMin(), timeRange.getMax());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (proto.hasTimeRange()) {
|
if (proto.hasTimeRange()) {
|
||||||
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
||||||
get.setTimeRange(timeRange.getMin(), timeRange.getMax());
|
get.setTimeRange(timeRange);
|
||||||
}
|
}
|
||||||
if (proto.hasFilter()) {
|
if (proto.hasFilter()) {
|
||||||
FilterProtos.Filter filter = proto.getFilter();
|
FilterProtos.Filter filter = proto.getFilter();
|
||||||
|
@ -807,7 +806,7 @@ public final class ProtobufUtil {
|
||||||
}
|
}
|
||||||
if (proto.hasTimeRange()) {
|
if (proto.hasTimeRange()) {
|
||||||
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
||||||
get.setTimeRange(timeRange.getMin(), timeRange.getMax());
|
get.setTimeRange(timeRange);
|
||||||
}
|
}
|
||||||
for (NameBytesPair attribute : proto.getAttributeList()) {
|
for (NameBytesPair attribute : proto.getAttributeList()) {
|
||||||
get.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
|
get.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
|
||||||
|
@ -951,13 +950,12 @@ public final class ProtobufUtil {
|
||||||
if (proto.getCfTimeRangeCount() > 0) {
|
if (proto.getCfTimeRangeCount() > 0) {
|
||||||
for (HBaseProtos.ColumnFamilyTimeRange cftr : proto.getCfTimeRangeList()) {
|
for (HBaseProtos.ColumnFamilyTimeRange cftr : proto.getCfTimeRangeList()) {
|
||||||
TimeRange timeRange = protoToTimeRange(cftr.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(cftr.getTimeRange());
|
||||||
scan.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(),
|
scan.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(), timeRange);
|
||||||
timeRange.getMin(), timeRange.getMax());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (proto.hasTimeRange()) {
|
if (proto.hasTimeRange()) {
|
||||||
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
||||||
scan.setTimeRange(timeRange.getMin(), timeRange.getMax());
|
scan.setTimeRange(timeRange);
|
||||||
}
|
}
|
||||||
if (proto.hasFilter()) {
|
if (proto.hasFilter()) {
|
||||||
FilterProtos.Filter filter = proto.getFilter();
|
FilterProtos.Filter filter = proto.getFilter();
|
||||||
|
|
|
@ -497,13 +497,12 @@ public final class ProtobufUtil {
|
||||||
if (proto.getCfTimeRangeCount() > 0) {
|
if (proto.getCfTimeRangeCount() > 0) {
|
||||||
for (HBaseProtos.ColumnFamilyTimeRange cftr : proto.getCfTimeRangeList()) {
|
for (HBaseProtos.ColumnFamilyTimeRange cftr : proto.getCfTimeRangeList()) {
|
||||||
TimeRange timeRange = protoToTimeRange(cftr.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(cftr.getTimeRange());
|
||||||
get.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(),
|
get.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(), timeRange);
|
||||||
timeRange.getMin(), timeRange.getMax());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (proto.hasTimeRange()) {
|
if (proto.hasTimeRange()) {
|
||||||
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
||||||
get.setTimeRange(timeRange.getMin(), timeRange.getMax());
|
get.setTimeRange(timeRange);
|
||||||
}
|
}
|
||||||
if (proto.hasFilter()) {
|
if (proto.hasFilter()) {
|
||||||
FilterProtos.Filter filter = proto.getFilter();
|
FilterProtos.Filter filter = proto.getFilter();
|
||||||
|
@ -920,7 +919,7 @@ public final class ProtobufUtil {
|
||||||
}
|
}
|
||||||
if (proto.hasTimeRange()) {
|
if (proto.hasTimeRange()) {
|
||||||
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
||||||
get.setTimeRange(timeRange.getMin(), timeRange.getMax());
|
get.setTimeRange(timeRange);
|
||||||
}
|
}
|
||||||
for (NameBytesPair attribute : proto.getAttributeList()) {
|
for (NameBytesPair attribute : proto.getAttributeList()) {
|
||||||
get.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
|
get.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
|
||||||
|
@ -1064,13 +1063,12 @@ public final class ProtobufUtil {
|
||||||
if (proto.getCfTimeRangeCount() > 0) {
|
if (proto.getCfTimeRangeCount() > 0) {
|
||||||
for (HBaseProtos.ColumnFamilyTimeRange cftr : proto.getCfTimeRangeList()) {
|
for (HBaseProtos.ColumnFamilyTimeRange cftr : proto.getCfTimeRangeList()) {
|
||||||
TimeRange timeRange = protoToTimeRange(cftr.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(cftr.getTimeRange());
|
||||||
scan.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(),
|
scan.setColumnFamilyTimeRange(cftr.getColumnFamily().toByteArray(), timeRange);
|
||||||
timeRange.getMin(), timeRange.getMax());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (proto.hasTimeRange()) {
|
if (proto.hasTimeRange()) {
|
||||||
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
TimeRange timeRange = protoToTimeRange(proto.getTimeRange());
|
||||||
scan.setTimeRange(timeRange.getMin(), timeRange.getMax());
|
scan.setTimeRange(timeRange);
|
||||||
}
|
}
|
||||||
if (proto.hasFilter()) {
|
if (proto.hasFilter()) {
|
||||||
FilterProtos.Filter filter = proto.getFilter();
|
FilterProtos.Filter filter = proto.getFilter();
|
||||||
|
|
Loading…
Reference in New Issue