HBASE-17654 Add support for table.existsAll in thrift2 THBaseservice (Yechao Chen)
This commit is contained in:
parent
84a9eb3f5c
commit
e8f9de7851
|
@ -39,6 +39,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -251,6 +252,23 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Boolean> existsAll(ByteBuffer table, List<TGet> gets) throws TIOError, TException {
|
||||
Table htable = getTable(table);
|
||||
try {
|
||||
boolean[] exists = htable.existsAll(getsFromThrift(gets));
|
||||
List<Boolean> result = new ArrayList<>(exists.length);
|
||||
for (boolean exist : exists) {
|
||||
result.add(exist);
|
||||
}
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
throw getTIOError(e);
|
||||
} finally {
|
||||
closeTable(htable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TResult get(ByteBuffer table, TGet get) throws TIOError, TException {
|
||||
Table htable = getTable(table);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -315,6 +315,21 @@ service THBaseService {
|
|||
2: required TGet tget
|
||||
) throws (1:TIOError io)
|
||||
|
||||
|
||||
/**
|
||||
* Test for the existence of columns in the table, as specified by the TGets.
|
||||
*
|
||||
* This will return an array of booleans. Each value will be true if the related Get matches
|
||||
* one or more keys, false if not.
|
||||
*/
|
||||
list<bool> existsAll(
|
||||
/** the table to check on */
|
||||
1: required binary table,
|
||||
|
||||
/** a list of TGets to check for */
|
||||
2: required list<TGet> tgets
|
||||
) throws (1:TIOError io)
|
||||
|
||||
/**
|
||||
* Method for getting data from a row.
|
||||
*
|
||||
|
|
|
@ -206,6 +206,34 @@ public class TestThriftHBaseServiceHandler {
|
|||
assertTrue(handler.exists(table, get));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistsAll() throws TIOError, TException {
|
||||
ThriftHBaseServiceHandler handler = createHandler();
|
||||
byte[] rowName1 = "testExistsAll1".getBytes();
|
||||
byte[] rowName2 = "testExistsAll2".getBytes();
|
||||
ByteBuffer table = wrap(tableAname);
|
||||
|
||||
List<TGet> gets = new ArrayList<>();
|
||||
gets.add(new TGet(wrap(rowName2)));
|
||||
gets.add(new TGet(wrap(rowName2)));
|
||||
List<Boolean> existsResult1 = handler.existsAll(table, gets);
|
||||
assertFalse(existsResult1.get(0));
|
||||
assertFalse(existsResult1.get(1));
|
||||
|
||||
List<TColumnValue> columnValues = new ArrayList<TColumnValue>();
|
||||
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
|
||||
columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
|
||||
List<TPut> puts = new ArrayList<TPut>();
|
||||
puts.add(new TPut(wrap(rowName1), columnValues));
|
||||
puts.add(new TPut(wrap(rowName2), columnValues));
|
||||
|
||||
handler.putMultiple(table, puts);
|
||||
List<Boolean> existsResult2 = handler.existsAll(table,gets );
|
||||
|
||||
assertTrue(existsResult2.get(0));
|
||||
assertTrue(existsResult2.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutGet() throws Exception {
|
||||
ThriftHBaseServiceHandler handler = createHandler();
|
||||
|
|
Loading…
Reference in New Issue