use of org.apache.hadoop.hbase.io.TimeRange in project hbase by apache.
the class ProtobufUtil method toIncrement.
/**
* Convert a protocol buffer Mutate to an Increment
*
* @param proto the protocol buffer Mutate to convert
* @return the converted client Increment
* @throws IOException
*/
public static Increment toIncrement(final MutationProto proto, final CellScanner cellScanner) throws IOException {
MutationType type = proto.getMutateType();
assert type == MutationType.INCREMENT : type.name();
Increment increment = toDelta((Bytes row) -> new Increment(row.get(), row.getOffset(), row.getLength()), Increment::add, proto, cellScanner);
if (proto.hasTimeRange()) {
TimeRange timeRange = toTimeRange(proto.getTimeRange());
increment.setTimeRange(timeRange.getMin(), timeRange.getMax());
}
return increment;
}
use of org.apache.hadoop.hbase.io.TimeRange in project hbase by apache.
the class MultiRowMutationEndpoint method matches.
private boolean matches(Region region, ClientProtos.Condition condition) throws IOException {
byte[] row = condition.getRow().toByteArray();
Filter filter = null;
byte[] family = null;
byte[] qualifier = null;
CompareOperator op = null;
ByteArrayComparable comparator = null;
if (condition.hasFilter()) {
filter = ProtobufUtil.toFilter(condition.getFilter());
} else {
family = condition.getFamily().toByteArray();
qualifier = condition.getQualifier().toByteArray();
op = CompareOperator.valueOf(condition.getCompareType().name());
comparator = ProtobufUtil.toComparator(condition.getComparator());
}
TimeRange timeRange = condition.hasTimeRange() ? ProtobufUtil.toTimeRange(condition.getTimeRange()) : TimeRange.allTime();
Get get = new Get(row);
if (family != null) {
checkFamily(region, family);
get.addColumn(family, qualifier);
}
if (filter != null) {
get.setFilter(filter);
}
if (timeRange != null) {
get.setTimeRange(timeRange.getMin(), timeRange.getMax());
}
boolean matches = false;
try (RegionScanner scanner = region.getScanner(new Scan(get))) {
// NOTE: Please don't use HRegion.get() instead,
// because it will copy cells to heap. See HBASE-26036
List<Cell> result = new ArrayList<>();
scanner.next(result);
if (filter != null) {
if (!result.isEmpty()) {
matches = true;
}
} else {
boolean valueIsNull = comparator.getValue() == null || comparator.getValue().length == 0;
if (result.isEmpty() && valueIsNull) {
matches = true;
} else if (result.size() > 0 && result.get(0).getValueLength() == 0 && valueIsNull) {
matches = true;
} else if (result.size() == 1 && !valueIsNull) {
Cell kv = result.get(0);
int compareResult = PrivateCellUtil.compareValue(kv, comparator);
matches = matches(op, compareResult);
}
}
}
return matches;
}
use of org.apache.hadoop.hbase.io.TimeRange in project hbase by apache.
the class TestSerialization method testGet.
@Test
public void testGet() throws Exception {
byte[] row = Bytes.toBytes("row");
byte[] fam = Bytes.toBytes("fam");
byte[] qf1 = Bytes.toBytes("qf1");
long ts = EnvironmentEdgeManager.currentTime();
int maxVersions = 2;
Get get = new Get(row);
get.addColumn(fam, qf1);
get.setTimeRange(ts, ts + 1);
get.readVersions(maxVersions);
ClientProtos.Get getProto = ProtobufUtil.toGet(get);
Get desGet = ProtobufUtil.toGet(getProto);
assertTrue(Bytes.equals(get.getRow(), desGet.getRow()));
Set<byte[]> set = null;
Set<byte[]> desSet = null;
for (Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()) {
assertTrue(desGet.getFamilyMap().containsKey(entry.getKey()));
set = entry.getValue();
desSet = desGet.getFamilyMap().get(entry.getKey());
for (byte[] qualifier : set) {
assertTrue(desSet.contains(qualifier));
}
}
assertEquals(get.getMaxVersions(), desGet.getMaxVersions());
TimeRange tr = get.getTimeRange();
TimeRange desTr = desGet.getTimeRange();
assertEquals(tr.getMax(), desTr.getMax());
assertEquals(tr.getMin(), desTr.getMin());
}
use of org.apache.hadoop.hbase.io.TimeRange in project hbase by apache.
the class ThriftUtilities method scanFromHBase.
public static TScan scanFromHBase(Scan in) throws IOException {
TScan out = new TScan();
out.setStartRow(in.getStartRow());
out.setStopRow(in.getStopRow());
out.setCaching(in.getCaching());
out.setMaxVersions(in.getMaxVersions());
for (Map.Entry<byte[], NavigableSet<byte[]>> family : in.getFamilyMap().entrySet()) {
if (family.getValue() != null && !family.getValue().isEmpty()) {
for (byte[] qualifier : family.getValue()) {
TColumn column = new TColumn();
column.setFamily(family.getKey());
column.setQualifier(qualifier);
out.addToColumns(column);
}
} else {
TColumn column = new TColumn();
column.setFamily(family.getKey());
out.addToColumns(column);
}
}
TTimeRange tTimeRange = new TTimeRange();
tTimeRange.setMinStamp(in.getTimeRange().getMin()).setMaxStamp(in.getTimeRange().getMax());
out.setTimeRange(tTimeRange);
out.setBatchSize(in.getBatch());
for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) {
out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())), ByteBuffer.wrap(attribute.getValue()));
}
try {
Authorizations authorizations = in.getAuthorizations();
if (authorizations != null) {
TAuthorization tAuthorization = new TAuthorization();
tAuthorization.setLabels(authorizations.getLabels());
out.setAuthorizations(tAuthorization);
}
} catch (DeserializationException e) {
throw new RuntimeException(e);
}
out.setReversed(in.isReversed());
out.setCacheBlocks(in.getCacheBlocks());
out.setReadType(readTypeFromHBase(in.getReadType()));
out.setLimit(in.getLimit());
out.setConsistency(consistencyFromHBase(in.getConsistency()));
out.setTargetReplicaId(in.getReplicaId());
for (Map.Entry<byte[], TimeRange> entry : in.getColumnFamilyTimeRange().entrySet()) {
if (entry.getValue() != null) {
TTimeRange timeRange = new TTimeRange();
timeRange.setMinStamp(entry.getValue().getMin()).setMaxStamp(entry.getValue().getMax());
out.putToColFamTimeRangeMap(ByteBuffer.wrap(entry.getKey()), timeRange);
}
}
if (in.getFilter() != null) {
try {
out.setFilterBytes(filterFromHBase(in.getFilter()));
} catch (IOException ioE) {
throw new RuntimeException(ioE);
}
}
return out;
}
use of org.apache.hadoop.hbase.io.TimeRange in project hbase by apache.
the class TestSimpleTimeRangeTracker method testRangeConstruction.
@Test
public void testRangeConstruction() throws IOException {
TimeRange defaultRange = TimeRange.allTime();
assertEquals(0L, defaultRange.getMin());
assertEquals(Long.MAX_VALUE, defaultRange.getMax());
assertTrue(defaultRange.isAllTime());
TimeRange oneArgRange = TimeRange.from(0L);
assertEquals(0L, oneArgRange.getMin());
assertEquals(Long.MAX_VALUE, oneArgRange.getMax());
assertTrue(oneArgRange.isAllTime());
TimeRange oneArgRange2 = TimeRange.from(1);
assertEquals(1, oneArgRange2.getMin());
assertEquals(Long.MAX_VALUE, oneArgRange2.getMax());
assertFalse(oneArgRange2.isAllTime());
TimeRange twoArgRange = TimeRange.between(0L, Long.MAX_VALUE);
assertEquals(0L, twoArgRange.getMin());
assertEquals(Long.MAX_VALUE, twoArgRange.getMax());
assertTrue(twoArgRange.isAllTime());
TimeRange twoArgRange2 = TimeRange.between(0L, Long.MAX_VALUE - 1);
assertEquals(0L, twoArgRange2.getMin());
assertEquals(Long.MAX_VALUE - 1, twoArgRange2.getMax());
assertFalse(twoArgRange2.isAllTime());
TimeRange twoArgRange3 = TimeRange.between(1, Long.MAX_VALUE);
assertEquals(1, twoArgRange3.getMin());
assertEquals(Long.MAX_VALUE, twoArgRange3.getMax());
assertFalse(twoArgRange3.isAllTime());
}
Aggregations