Java 类org.apache.hadoop.hbase.client.Result 实例源码
项目:ditb
文件:TestTimeRangeMapRed.java
private void verify(final Table table) throws IOException {
Scan scan = new Scan();
scan.addColumn(FAMILY_NAME, COLUMN_NAME);
scan.setMaxVersions(1);
ResultScanner scanner = table.getScanner(scan);
for (Result r: scanner) {
for (Cell kv : r.listCells()) {
log.debug(Bytes.toString(r.getRow()) + "\t" + Bytes.toString(CellUtil.cloneFamily(kv))
+ "\t" + Bytes.toString(CellUtil.cloneQualifier(kv))
+ "\t" + kv.getTimestamp() + "\t" + Bytes.toBoolean(CellUtil.cloneValue(kv)));
org.junit.Assert.assertEquals(TIMESTAMP.get(kv.getTimestamp()),
(Boolean)Bytes.toBoolean(CellUtil.cloneValue(kv)));
}
}
scanner.close();
}
项目:ditb
文件:TestTimeRangeMapRed.java
@Override
public void map(ImmutableBytesWritable key, Result result,
Context context)
throws IOException {
List<Long> tsList = new ArrayList<Long>();
for (Cell kv : result.listCells()) {
tsList.add(kv.getTimestamp());
}
List<Put> puts = new ArrayList<>();
for (Long ts : tsList) {
Put put = new Put(key.get());
put.setDurability(Durability.SKIP_WAL);
put.add(FAMILY_NAME, COLUMN_NAME, ts, Bytes.toBytes(true));
puts.add(put);
}
table.put(puts);
}
项目:SparkDemo
文件:MyClass.java
public static void QueryByCondition1(String tableName) {
HTablePool pool = new HTablePool(configuration, 1000);
HTable table = (HTable) pool.getTable(tableName);
try {
Get scan = new Get("abcdef".getBytes());// 根据rowkey查询
Result r = table.get(scan);
System.out.println("获得到rowkey:" + new String(r.getRow()));
for (KeyValue keyValue : r.raw()) {
System.out.println("列:" + new String(keyValue.getFamily())
+ "====值:" + new String(keyValue.getValue()));
}
} catch (IOException e) {
e.printStackTrace();
}
}
项目:ditb
文件:TestReplicationChangingPeerRegionservers.java
private void doPutTest(byte[] row) throws IOException, InterruptedException {
Put put = new Put(row);
put.add(famName, row, row);
if (htable1 == null) {
htable1 = utility1.getConnection().getTable(tableName);
}
htable1.put(put);
Get get = new Get(row);
for (int i = 0; i < NB_RETRIES; i++) {
if (i == NB_RETRIES - 1) {
fail("Waited too much time for put replication");
}
Result res = htable2.get(get);
if (res.size() == 0) {
LOG.info("Row not available");
Thread.sleep(SLEEP_TIME);
} else {
assertArrayEquals(res.value(), row);
break;
}
}
}
项目:SparkDemo
文件:MyClass.java
public static void QueryByCondition2(String tableName) {
try {
HTablePool pool = new HTablePool(configuration, 1000);
HTable table = (HTable) pool.getTable(tableName);
Filter filter = new SingleColumnValueFilter(Bytes
.toBytes("column1"), null, CompareOp.EQUAL, Bytes
.toBytes("aaa")); // 当列column1的值为aaa时进行查询
Scan s = new Scan();
s.setFilter(filter);
ResultScanner rs = table.getScanner(s);
for (Result r : rs) {
System.out.println("获得到rowkey:" + new String(r.getRow()));
for (KeyValue keyValue : r.raw()) {
System.out.println("列:" + new String(keyValue.getFamily())
+ "====值:" + new String(keyValue.getValue()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
项目:ditb
文件:TestVisibilityLabels.java
@Test(timeout = 60 * 1000)
public void testVisibilityLabelsOnRSRestart() throws Exception {
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster()
.getRegionServerThreads();
for (RegionServerThread rsThread : regionServerThreads) {
rsThread.getRegionServer().abort("Aborting ");
}
// Start one new RS
RegionServerThread rs = TEST_UTIL.getHBaseCluster().startRegionServer();
waitForLabelsRegionAvailability(rs.getRegionServer());
try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
+ ")", PRIVATE);) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET));
ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3);
assertTrue(next.length == 1);
}
}
项目:ditb
文件:TestSCVFWithMiniCluster.java
private void verify(Scan scan) throws IOException {
ResultScanner scanner = htable.getScanner(scan);
Iterator<Result> it = scanner.iterator();
/* Then */
int count = 0;
try {
while (it.hasNext()) {
it.next();
count++;
}
} finally {
scanner.close();
}
assertEquals(expected, count);
}
项目:ditb
文件:IntegrationTestBigLinkedList.java
private static CINode findStartNode(Table table, byte[] startKey) throws IOException {
Scan scan = new Scan();
scan.setStartRow(startKey);
scan.setBatch(1);
scan.addColumn(FAMILY_NAME, COLUMN_PREV);
long t1 = System.currentTimeMillis();
ResultScanner scanner = table.getScanner(scan);
Result result = scanner.next();
long t2 = System.currentTimeMillis();
scanner.close();
if ( result != null) {
CINode node = getCINode(result, new CINode());
System.out.printf("FSR %d %s\n", t2 - t1, Bytes.toStringBinary(node.key));
return node;
}
System.out.println("FSR " + (t2 - t1));
return null;
}
项目:mumu-hbase
文件:HBaseFilterOperation.java
/**
* 使用行过滤器 选择大于rowKey的行
*
* @param tableName 表名
* @param rowKey 行健
* @param count 数量
*/
public void rowFilter(String tableName, String rowKey, int count) {
HBaseConfiguration hBaseConfiguration = new HBaseConfiguration();
Table table = hBaseConfiguration.table(tableName);
Scan scan = new Scan();
//使用行过滤器 选择大于 rowkey的行
//scan.setFilter(new RowFilter(CompareFilter.CompareOp.GREATER, new BinaryComparator(Bytes.toBytes(rowKey))));//直接行健
//scan.setFilter(new RowFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL, new RegexStringComparator("row.*")));//正则表达式
//scan.setFilter(new RowFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL, new SubstringComparator("row")));//字符串包含
scan.setFilter(new RowFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL, new BinaryPrefixComparator("row".getBytes())));//字符串前缀
scan.setCaching(10);
scan.setBatch(10);
try {
ResultScanner scanner = table.getScanner(scan);
Result[] results = scanner.next(count);
HBaseResultUtil.print(results);
} catch (IOException e) {
e.printStackTrace();
}
}
项目:HBase-High-Performance-Cookbook
文件:HBaseRegularClient.java
/**
* Getting all records a row from an existing SS tables
* @method getAllRecord
* @inputParameters hbaseBtable Name used
* @return type: no return type as its a void method
*
**/
@SuppressWarnings({ "deprecation", "resource" })
public static void getAllRecord(String myHbaseBtableName) {
ResultScanner hbaseBSs = null;
try {
HTable hbaseBtable = new HTable(hbaseBconf, myHbaseBtableName);
Scan hbaseBScan = new Scan();
hbaseBSs = hbaseBtable.getScanner(hbaseBScan);
for (Result r : hbaseBSs) {
for (KeyValue hbaseBkv : r.raw()) {
System.out.print(new String(hbaseBkv.getRow()) + " ");
System.out.print(new String(hbaseBkv.getFamily()) + ":");
System.out.print(new String(hbaseBkv.getQualifier()) + " ");
System.out.print(hbaseBkv.getTimestamp() + " ");
System.out.println(new String(hbaseBkv.getValue()));
}
}
} catch (IOException eio) {
eip.printStackTrace();
} finally {
if (hbaseBSs != null) hbaseBSs.close();
// closing the ss hbaseBtable
}
}
项目:ditb
文件:MetaTableAccessor.java
/**
* @param connection connection we're using
* @param serverName server whose regions we're interested in
* @return List of user regions installed on this server (does not include
* catalog regions).
* @throws IOException
*/
public static NavigableMap<HRegionInfo, Result>
getServerUserRegions(Connection connection, final ServerName serverName)
throws IOException {
final NavigableMap<HRegionInfo, Result> hris = new TreeMap<HRegionInfo, Result>();
// Fill the above hris map with entries from hbase:meta that have the passed
// servername.
CollectingVisitor<Result> v = new CollectingVisitor<Result>() {
@Override
void add(Result r) {
if (r == null || r.isEmpty()) return;
RegionLocations locations = getRegionLocations(r);
if (locations == null) return;
for (HRegionLocation loc : locations.getRegionLocations()) {
if (loc != null) {
if (loc.getServerName() != null && loc.getServerName().equals(serverName)) {
hris.put(loc.getRegionInfo(), r);
}
}
}
}
};
fullScan(connection, v);
return hris;
}
项目:ditb
文件:TestRemoteTable.java
@Test
public void testCheckAndDelete() throws IOException {
Get get = new Get(ROW_1);
Result result = remoteTable.get(get);
byte[] value1 = result.getValue(COLUMN_1, QUALIFIER_1);
byte[] value2 = result.getValue(COLUMN_2, QUALIFIER_2);
assertNotNull(value1);
assertTrue(Bytes.equals(VALUE_1, value1));
assertNull(value2);
assertTrue(remoteTable.exists(get));
assertEquals(1, remoteTable.existsAll(Collections.singletonList(get)).length);
Delete delete = new Delete(ROW_1);
remoteTable.checkAndDelete(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1, delete);
assertFalse(remoteTable.exists(get));
Put put = new Put(ROW_1);
put.add(COLUMN_1, QUALIFIER_1, VALUE_1);
remoteTable.put(put);
assertTrue(remoteTable.checkAndPut(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1,
put));
assertFalse(remoteTable.checkAndPut(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_2,
put));
}
项目:ditb
文件:TestVisibilityLabels.java
@Test
public void testSimpleVisibilityLabels() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CONFIDENTIAL,
PRIVATE + "|" + CONFIDENTIAL)) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE));
ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3);
assertTrue(next.length == 2);
CellScanner cellScanner = next[0].cellScanner();
cellScanner.advance();
Cell current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row1, 0, row1.length));
cellScanner = next[1].cellScanner();
cellScanner.advance();
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length));
}
}
项目:ditb
文件:TestTableInputFormatScanBase.java
/**
* Pass the key and value to reduce.
*
* @param key The key, here "aaa", "aab" etc.
* @param value The value is the same as the key.
* @param context The task context.
* @throws IOException When reading the rows fails.
*/
@Override
public void map(ImmutableBytesWritable key, Result value,
Context context)
throws IOException, InterruptedException {
if (value.size() != 1) {
throw new IOException("There should only be one input column");
}
Map<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>
cf = value.getMap();
if(!cf.containsKey(INPUT_FAMILY)) {
throw new IOException("Wrong input columns. Missing: '" +
Bytes.toString(INPUT_FAMILY) + "'.");
}
String val = Bytes.toStringBinary(value.getValue(INPUT_FAMILY, null));
LOG.info("map: key -> " + Bytes.toStringBinary(key.get()) +
", value -> " + val);
context.write(key, key);
}
项目:springboot_cwenao
文件:HbaseAccountInfoMapperImpl.java
@Override
public List<UserInfo> findAll(String tablename, String family) {
byte[] cf_info = family.getBytes();
byte[] age_info = Bytes.toBytes("age");
byte[] id_info = Bytes.toBytes("id");
byte[] username_info = Bytes.toBytes("userName");
return hbaseTemplate.find(tablename, family, new RowMapper<UserInfo>() {
@Override
public UserInfo mapRow(Result result, int rowNum) throws Exception {
UserInfo u = new UserInfo();
u.setId(Bytes.toString(result.getValue(cf_info,id_info)));
u.setUserName(Bytes.toString(result.getValue(cf_info,username_info)));
u.setAge(Bytes.toInt(result.getValue(cf_info,age_info)));
return u;
}
});
}
项目:ditb
文件:TestServerSideScanMetricsFromClientSide.java
/**
* Run the scan to completetion and check the metric against the specified value
* @param scan
* @param metricKey
* @param expectedValue
* @throws Exception
*/
public void testMetric(Scan scan, String metricKey, long expectedValue) throws Exception {
assertTrue("Scan should be configured to record metrics", scan.isScanMetricsEnabled());
ResultScanner scanner = TABLE.getScanner(scan);
// Iterate through all the results
for (Result r : scanner) {
}
scanner.close();
ScanMetrics metrics = scan.getScanMetrics();
assertTrue("Metrics are null", metrics != null);
assertTrue("Metric : " + metricKey + " does not exist", metrics.hasCounter(metricKey));
final long actualMetricValue = metrics.getCounter(metricKey).get();
assertEquals("Metric: " + metricKey + " Expected: " + expectedValue + " Actual: "
+ actualMetricValue, expectedValue, actualMetricValue);
}
项目:SkyEye
文件:TraceTimeConsumeRowMapper.java
@Override
public TraceTimeConsumeDto mapRow(Result res, int rowNum) throws Exception {
TraceTimeConsumeDto dto = new TraceTimeConsumeDto();
Map<byte[], byte[]> familyMap = res.getFamilyMap(Constants.TABLE_TIME_CONSUME_COLUMN_FAMILY.getBytes());
Set<Map.Entry<byte[], byte[]>> entrySet = familyMap.entrySet();
for (Map.Entry<byte[], byte[]> en : entrySet) {
dto.setTraceId(new String(en.getKey())).setConsumeTime(RadixUtil.bytesToLong(en.getValue()));
}
String[] ss = new String(res.getRow()).split(Constants.UNDER_LINE);
String iface = ss[0];
String method = ss[1];
Long startTime = Long.parseLong(ss[2]);
Long endTime = startTime + dto.getConsumeTime();
String rowKey = new String(res.getRow());
dto.setIface(iface).setMethod(method).setStartTime(startTime).setEndTime(endTime).setRowKey(rowKey);
return dto;
}
项目:ditb
文件:TestHRegion.java
static void verifyData(HRegion newReg, int startRow, int numRows, byte[] qf, byte[]... families)
throws IOException {
for (int i = startRow; i < startRow + numRows; i++) {
byte[] row = Bytes.toBytes("" + i);
Get get = new Get(row);
for (byte[] family : families) {
get.addColumn(family, qf);
}
Result result = newReg.get(get);
Cell[] raw = result.rawCells();
assertEquals(families.length, result.size());
for (int j = 0; j < families.length; j++) {
assertTrue(CellUtil.matchingRow(raw[j], row));
assertTrue(CellUtil.matchingFamily(raw[j], families[j]));
assertTrue(CellUtil.matchingQualifier(raw[j], qf));
}
}
}
项目:ditb
文件:TestVisibilityLabelsWithACL.java
@Test
public void testGetForSuperUserWithFewerLabelAuths() throws Throwable {
String[] auths = { SECRET };
String user = "admin";
VisibilityClient.setAuths(TEST_UTIL.getConnection(), auths, user);
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ "&!" + PRIVATE, SECRET + "&!" + PRIVATE);
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
Get g = new Get(row1);
g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
try (Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(table.getName())) {
Result result = t.get(g);
assertTrue(!result.isEmpty());
}
return null;
}
};
SUPERUSER.runAs(scanAction);
}
项目:ditb
文件:PerfScanBase.java
private OpResult executeRandomGet() throws IOException, ParseException {
if (!hasRandomGet()) {
return new OpResult("random get not supported", 1, 1);
}
Table table = conn.getTable(opTblName);
BufferedReader br = new BufferedReader(new FileReader(queryFilePath));
String line;
int counter = 0;
long totalTime = 0;
while ((line = br.readLine()) != null) {
Get get = getIndexTableGet(line);
long startTime = System.currentTimeMillis();
Result result = processGet(table, get);
totalTime += System.currentTimeMillis() - startTime;
counter += recordsInOneResult(result);
if (counter >= nbGet) break;
}
OpResult ret = new OpResult("random get", counter, totalTime);
br.close();
table.close();
return ret;
}
项目:ditb
文件:TestMultithreadedTableMapper.java
/**
* Pass the key, and reversed value to reduce
*
* @param key
* @param value
* @param context
* @throws IOException
*/
public void map(ImmutableBytesWritable key, Result value,
Context context)
throws IOException, InterruptedException {
if (value.size() != 1) {
throw new IOException("There should only be one input column");
}
Map<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>
cf = value.getMap();
if(!cf.containsKey(INPUT_FAMILY)) {
throw new IOException("Wrong input columns. Missing: '" +
Bytes.toString(INPUT_FAMILY) + "'.");
}
// Get the original value and reverse it
String originalValue = Bytes.toString(value.getValue(INPUT_FAMILY, null));
StringBuilder newValue = new StringBuilder(originalValue);
newValue.reverse();
// Now set the value to be collected
Put outval = new Put(key.get());
outval.add(OUTPUT_FAMILY, null, Bytes.toBytes(newValue.toString()));
context.write(key, outval);
}
项目:ditb
文件:UniWorkload.java
@Override public String parseResult(Result result) {
int rowkey = Bytes.toInt(result.getRow(), 4);
int a = Bytes.toInt(result.getValue(FAMILY_NAME, Bytes.toBytes("a")));
int b = Bytes.toInt(result.getValue(FAMILY_NAME, Bytes.toBytes("b")));
int c = Bytes.toInt(result.getValue(FAMILY_NAME, Bytes.toBytes("c")));
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("rowkey=").append(rowkey).append(",");
sb.append("a=").append(a).append(",");
sb.append("b=").append(b).append(",");
sb.append("c=").append(c).append(",");
sb.append("other ").append(nbTotalColumns - DITBUniRecord.DATA_COLUMN_OFFSET)
.append(" data columns not shown");
sb.append("}");
return sb.toString();
}
项目:ditb
文件:ThriftUtilities.java
/**
* Creates a {@link TResult} (Thrift) from a {@link Result} (HBase).
*
* @param in the <code>Result</code> to convert
*
* @return converted result, returns an empty result if the input is <code>null</code>
*/
public static TResult resultFromHBase(Result in) {
Cell[] raw = in.rawCells();
TResult out = new TResult();
byte[] row = in.getRow();
if (row != null) {
out.setRow(in.getRow());
}
List<TColumnValue> columnValues = new ArrayList<TColumnValue>();
for (Cell kv : raw) {
TColumnValue col = new TColumnValue();
col.setFamily(CellUtil.cloneFamily(kv));
col.setQualifier(CellUtil.cloneQualifier(kv));
col.setTimestamp(kv.getTimestamp());
col.setValue(CellUtil.cloneValue(kv));
if (kv.getTagsLength() > 0) {
col.setTags(CellUtil.getTagArray(kv));
}
columnValues.add(col);
}
out.setColumnValues(columnValues);
return out;
}
项目:ditb
文件:TestMetaTableAccessor.java
public static void assertMetaLocation(Table meta, byte[] row, ServerName serverName,
long seqNum, int replicaId, boolean checkSeqNum) throws IOException {
Get get = new Get(row);
Result result = meta.get(get);
assertTrue(Bytes.equals(
result.getValue(HConstants.CATALOG_FAMILY, MetaTableAccessor.getServerColumn(replicaId)),
Bytes.toBytes(serverName.getHostAndPort())));
assertTrue(Bytes.equals(
result.getValue(HConstants.CATALOG_FAMILY, MetaTableAccessor.getStartCodeColumn(replicaId)),
Bytes.toBytes(serverName.getStartcode())));
if (checkSeqNum) {
assertTrue(Bytes.equals(
result.getValue(HConstants.CATALOG_FAMILY, MetaTableAccessor.getSeqNumColumn(replicaId)),
Bytes.toBytes(seqNum)));
}
}
项目:ditb
文件:IRScannerInParallel.java
@Override public Result next() throws IOException {
if (abortException != null) throw abortException;
if (scannerList.isEmpty()) return null;
Result res = null;
long timeStart = System.currentTimeMillis();
while (res == null) {
res = scannerList.get(scannerIndex).next();
if (res != null) {
scannerIndex = (scannerIndex + 1) % scannerList.size();
} else {
ResultScanner scanner = scannerList.remove(scannerIndex);
IOUtils.closeQuietly(scanner);
if (scannerIndex >= scannerList.size()) {
scannerIndex = 0;
}
addNewScanner(scannerList.isEmpty());
if (scannerList.isEmpty()) {
waitUntilDone();
if (scannerList.isEmpty()) {
break;
}
}
}
}
totalScanTime += (System.currentTimeMillis() - timeStart);
++totalNumberOfRecords;
return res;
}
项目:ditb
文件:TestReplicationChangingPeerRegionservers.java
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Starting and stopping replication can make us miss new logs,
// rolling like this makes sure the most recent one gets added to the queue
for (JVMClusterUtil.RegionServerThread r :
utility1.getHBaseCluster().getRegionServerThreads()) {
utility1.getHBaseAdmin().rollWALWriter(r.getRegionServer().getServerName());
}
utility1.deleteTableData(tableName);
// truncating the table will send one Delete per row to the slave cluster
// in an async fashion, which is why we cannot just call deleteTableData on
// utility2 since late writes could make it to the slave in some way.
// Instead, we truncate the first table and wait for all the Deletes to
// make it to the slave.
Scan scan = new Scan();
int lastCount = 0;
for (int i = 0; i < NB_RETRIES; i++) {
if (i == NB_RETRIES - 1) {
fail("Waited too much time for truncate");
}
ResultScanner scanner = htable2.getScanner(scan);
Result[] res = scanner.next(NB_ROWS_IN_BIG_BATCH);
scanner.close();
if (res.length != 0) {
if (res.length < lastCount) {
i--; // Don't increment timeout if we make progress
}
lastCount = res.length;
LOG.info("Still got " + res.length + " rows");
Thread.sleep(SLEEP_TIME);
} else {
break;
}
}
}
项目:ditb
文件:TestRowCounter.java
@Test
@SuppressWarnings({ "deprecation", "unchecked" })
public void shouldRegInReportEveryIncomingRow() throws IOException {
int iterationNumber = 999;
RowCounter.RowCounterMapper mapper = new RowCounter.RowCounterMapper();
Reporter reporter = mock(Reporter.class);
for (int i = 0; i < iterationNumber; i++)
mapper.map(mock(ImmutableBytesWritable.class), mock(Result.class),
mock(OutputCollector.class), reporter);
Mockito.verify(reporter, times(iterationNumber)).incrCounter(
any(Enum.class), anyInt());
}
项目:ditb
文件:TestMetaTableAccessor.java
/**
* Tests whether maximum of masters system time versus RSs local system time is used
*/
@Test
public void testMastersSystemTimeIsUsedInUpdateLocations() throws IOException {
long regionId = System.currentTimeMillis();
HRegionInfo regionInfo = new HRegionInfo(TableName.valueOf("table_foo"),
HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW, false, regionId, 0);
ServerName sn = ServerName.valueOf("bar", 0, 0);
Table meta = MetaTableAccessor.getMetaHTable(connection);
try {
List<HRegionInfo> regionInfos = Lists.newArrayList(regionInfo);
MetaTableAccessor.addRegionsToMeta(connection, regionInfos, 1);
long masterSystemTime = EnvironmentEdgeManager.currentTime() + 123456789;
MetaTableAccessor.updateRegionLocation(connection, regionInfo, sn, 1, masterSystemTime);
Get get = new Get(regionInfo.getRegionName());
Result result = meta.get(get);
Cell serverCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY,
MetaTableAccessor.getServerColumn(0));
Cell startCodeCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY,
MetaTableAccessor.getStartCodeColumn(0));
Cell seqNumCell = result.getColumnLatestCell(HConstants.CATALOG_FAMILY,
MetaTableAccessor.getSeqNumColumn(0));
assertNotNull(serverCell);
assertNotNull(startCodeCell);
assertNotNull(seqNumCell);
assertTrue(serverCell.getValueLength() > 0);
assertTrue(startCodeCell.getValueLength() > 0);
assertTrue(seqNumCell.getValueLength() > 0);
assertEquals(masterSystemTime, serverCell.getTimestamp());
assertEquals(masterSystemTime, startCodeCell.getTimestamp());
assertEquals(masterSystemTime, seqNumCell.getTimestamp());
} finally {
meta.close();
}
}
项目:ditb
文件:HBaseTestCase.java
protected void assertResultEquals(final HRegion region, final byte [] row,
final byte [] family, final byte [] qualifier, final long timestamp,
final byte [] value)
throws IOException {
Get get = new Get(row);
get.setTimeStamp(timestamp);
Result res = region.get(get);
NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> map =
res.getMap();
byte [] res_value = map.get(family).get(qualifier).get(timestamp);
if (value == null) {
assertEquals(Bytes.toString(family) + " " + Bytes.toString(qualifier) +
" at timestamp " + timestamp, null, res_value);
} else {
if (res_value == null) {
fail(Bytes.toString(family) + " " + Bytes.toString(qualifier) +
" at timestamp " + timestamp + "\" was expected to be \"" +
Bytes.toStringBinary(value) + " but was null");
}
if (res_value != null) {
assertEquals(Bytes.toString(family) + " " + Bytes.toString(qualifier) +
" at timestamp " +
timestamp, value, new String(res_value));
}
}
}
项目:ditb
文件:HRegionInfo.java
/**
* Extract a HRegionInfo and ServerName from catalog table {@link Result}.
* @param r Result to pull from
* @return A pair of the {@link HRegionInfo} and the {@link ServerName}
* (or null for server address if no address set in hbase:meta).
* @deprecated use MetaTableAccessor methods for interacting with meta layouts
*/
@Deprecated
public static Pair<HRegionInfo, ServerName> getHRegionInfoAndServerName(final Result r) {
HRegionInfo info =
getHRegionInfo(r, HConstants.REGIONINFO_QUALIFIER);
ServerName sn = getServerName(r);
return new Pair<HRegionInfo, ServerName>(info, sn);
}
项目:ditb
文件:AccessController.java
@Override
public boolean preScannerNext(final ObserverContext<RegionCoprocessorEnvironment> c,
final InternalScanner s, final List<Result> result,
final int limit, final boolean hasNext) throws IOException {
requireScannerOwner(s);
return hasNext;
}
项目:ditb
文件:MultiThreadedReader.java
protected void verifyResultsAndUpdateMetrics(boolean verify, Get[] gets, long elapsedNano,
Result[] results, Table table, boolean isNullExpected)
throws IOException {
totalOpTimeMs.addAndGet(elapsedNano / 1000000);
numKeys.addAndGet(gets.length);
int i = 0;
for (Result result : results) {
verifyResultsAndUpdateMetricsOnAPerGetBasis(verify, gets[i++], result, table,
isNullExpected);
}
}
项目:ditb
文件:HRegion.java
/**
* Constructor with all the parameters.
*
* @param result Any of the Result.
* @param flushSequenceId Generated sequence id if the memstores were flushed else -1.
* @param failureReason Reason why we couldn't flush, or null.
*/
FlushResultImpl(Result result, long flushSequenceId, String failureReason,
boolean wroteFlushMarker) {
this.result = result;
this.flushSequenceId = flushSequenceId;
this.failureReason = failureReason;
this.wroteFlushWalMarker = wroteFlushMarker;
}
项目:QDrill
文件:HBasePStore.java
private V value(Result result) {
try {
return config.getSerializer().deserialize(result.value());
} catch (IOException e) {
throw new DrillRuntimeException(e);
}
}
项目:ditb
文件:MetaTableAccessor.java
/**
* @param t Table to use (will be closed when done).
* @param g Get to run
* @throws IOException
*/
private static Result get(final Table t, final Get g) throws IOException {
try {
return t.get(g);
} finally {
t.close();
}
}
项目:ditb
文件:MetaTableAccessor.java
/**
* Returns the HRegionLocation from meta for the given region
* @param connection connection we're using
* @param regionInfo region information
* @return HRegionLocation for the given region
* @throws IOException
*/
public static HRegionLocation getRegionLocation(Connection connection,
HRegionInfo regionInfo) throws IOException {
byte[] row = getMetaKeyForRegion(regionInfo);
Get get = new Get(row);
get.addFamily(HConstants.CATALOG_FAMILY);
Result r = get(getMetaHTable(connection), get);
return getRegionLocation(r, regionInfo, regionInfo.getReplicaId());
}
项目:ditb
文件:TestGroupingTableMap.java
@Test
@SuppressWarnings({ "deprecation", "unchecked" })
public void shouldNotCallCollectonSinceFindUniqueKeyValueMoreThanOnes()
throws Exception {
GroupingTableMap gTableMap = null;
try {
Result result = mock(Result.class);
Reporter reporter = mock(Reporter.class);
gTableMap = new GroupingTableMap();
Configuration cfg = new Configuration();
cfg.set(GroupingTableMap.GROUP_COLUMNS, "familyA:qualifierA familyB:qualifierB");
JobConf jobConf = new JobConf(cfg);
gTableMap.configure(jobConf);
byte[] row = {};
List<Cell> keyValues = ImmutableList.<Cell>of(
new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("1111")),
new KeyValue(row, "familyA".getBytes(), "qualifierA".getBytes(), Bytes.toBytes("2222")),
new KeyValue(row, "familyB".getBytes(), "qualifierB".getBytes(), Bytes.toBytes("3333")));
when(result.listCells()).thenReturn(keyValues);
OutputCollector<ImmutableBytesWritable, Result> outputCollectorMock =
mock(OutputCollector.class);
gTableMap.map(null, result, outputCollectorMock, reporter);
verify(result).listCells();
verifyZeroInteractions(outputCollectorMock);
} finally {
if (gTableMap != null)
gTableMap.close();
}
}
项目:easyhbase
文件:ParallelResultScanner.java
private Result nextInternal() throws IOException {
Result result = null;
int indexOfResultToUse = -1;
for (int i = 0; i < this.scanTasks.size(); ++i) {
ScanTask scanTask = this.scanTasks.get(i);
// fail fast in case of errors
checkTask(scanTask);
if (nextResults[i] == null) {
try {
nextResults[i] = scanTask.getResult();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
}
if (nextResults[i] == null) {
continue;
}
}
if (result == null || Bytes.compareTo(keyDistributor.getOriginalKey(nextResults[i]
.getRow()),
keyDistributor.getOriginalKey(result.getRow())) < 0) {
result = nextResults[i];
indexOfResultToUse = i;
}
}
if (indexOfResultToUse >= 0) {
nextResults[indexOfResultToUse] = null;
}
return result;
}
项目:ditb
文件:QuotaTableUtil.java
private static Quotas getQuotas(final Connection connection, final byte[] rowKey,
final byte[] qualifier) throws IOException {
Get get = new Get(rowKey);
get.addColumn(QUOTA_FAMILY_INFO, qualifier);
Result result = doGet(connection, get);
if (result.isEmpty()) {
return null;
}
return quotasFromData(result.getValue(QUOTA_FAMILY_INFO, qualifier));
}
项目:ditb
文件:RegionCoprocessorHost.java
/**
* @param append append object
* @return result to return to client if default operation should be
* bypassed, null otherwise
* @throws IOException if an error occurred on the coprocessor
*/
public Result preAppend(final Append append) throws IOException {
return execOperationWithResult(true, null,
coprocessors.isEmpty() ? null : new RegionOperationWithResult<Result>() {
@Override
public void call(RegionObserver oserver, ObserverContext<RegionCoprocessorEnvironment> ctx)
throws IOException {
setResult(oserver.preAppend(ctx, append));
}
});
}