本文整理了Java中org.apache.hadoop.hbase.client.Table.exists()
方法的一些代码示例,展示了Table.exists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table.exists()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Table
类名称:Table
方法名:exists
[英]Test for the existence of columns in the table, as specified by the Gets.
This will return an array of booleans. Each value will be true if the related Get matches one or more keys, false if not.
This is a server-side call so it prevents any data from being transferred to the client.
[中]测试表中是否存在Gets指定的列。
这将返回一系列布尔值。如果相关Get匹配一个或多个键,则每个值都将为true,否则为false。
这是一个服务器端调用,因此它可以防止任何数据传输到客户端。
代码示例来源:origin: apache/hbase
/**
* Test for the existence of columns in the table, as specified by the Gets.
* This will return an array of booleans. Each value will be true if the related Get matches
* one or more keys, false if not.
* This is a server-side call so it prevents any data from being transferred to
* the client.
*
* @param gets the Gets
* @return Array of boolean. True if the specified Get matches one or more keys, false if not.
* @throws IOException e
* @deprecated since 2.0 version and will be removed in 3.0 version.
* use {@link #exists(List)}
*/
@Deprecated
default boolean[] existsAll(List<Get> gets) throws IOException {
return exists(gets);
}
代码示例来源:origin: apache/hbase
public void testCheckAndDelete(Connection connection, String tableName) throws IOException {
createTable(thriftAdmin, tableName);
try (Table table = connection.getTable(TableName.valueOf(tableName))){
Get get = new Get(ROW_1);
Result result = table.get(get);
byte[] value1 = result.getValue(FAMILYA, QUALIFIER_1);
byte[] value2 = result.getValue(FAMILYB, QUALIFIER_2);
assertNotNull(value1);
assertTrue(Bytes.equals(VALUE_1, value1));
assertNull(value2);
assertTrue(table.exists(get));
assertEquals(1, table.existsAll(Collections.singletonList(get)).length);
Delete delete = new Delete(ROW_1);
table.checkAndMutate(ROW_1, FAMILYA).qualifier(QUALIFIER_1)
.ifEquals(VALUE_1).thenDelete(delete);
assertFalse(table.exists(get));
Put put = new Put(ROW_1);
put.addColumn(FAMILYA, QUALIFIER_1, VALUE_1);
table.put(put);
assertTrue(table.checkAndMutate(ROW_1, FAMILYA).qualifier(QUALIFIER_1)
.ifEquals(VALUE_1).thenPut(put));
assertFalse(table.checkAndMutate(ROW_1, FAMILYA).qualifier(QUALIFIER_1)
.ifEquals(VALUE_2).thenPut(put));
}
}
代码示例来源:origin: apache/hbase
/**
* Test for the existence of columns in the table, as specified by the Get.
* <p>
*
* This will return true if the Get matches one or more keys, false if not.
* <p>
*
* This is a server-side call so it prevents any data from being transfered to
* the client.
*
* @param get the Get
* @return true if the specified Get matches one or more keys, false if not
* @throws IOException e
*/
default boolean exists(Get get) throws IOException {
return exists(Collections.singletonList(get))[0];
}
代码示例来源:origin: apache/hbase
private void assertNotExists(int start, int end) throws IOException {
for (int i = start; i < end; i++) {
assertFalse(TABLE.exists(new Get(Bytes.toBytes(i))));
}
}
代码示例来源:origin: apache/hbase
@Override
public boolean evaluate() throws Exception {
try (Table table = UTIL1.getConnection().getTable(TABLE_NAME)) {
return table.exists(new Get(Bytes.toBytes(0)));
}
}
代码示例来源:origin: apache/hbase
@Override
public boolean exists(ByteBuffer table, TGet get) throws TIOError, TException {
Table htable = getTable(table);
try {
return htable.exists(getFromThrift(get));
} catch (IOException e) {
throw getTIOError(e);
} finally {
closeTable(htable);
}
}
代码示例来源:origin: apache/drill
@Override
public boolean contains(String key) {
try {
Get get = new Get(row(key));
get.addColumn(FAMILY, QUALIFIER);
return hbaseTable.exists(get);
} catch (IOException e) {
throw UserException
.dataReadError(e)
.message("Caught error while checking row existence '%s' for table '%s'", key, hbaseTableName)
.build(logger);
}
}
代码示例来源:origin: apache/hbase
@Test
public void testHTableExistsMethodMultipleRegionsSingleGet() throws Exception {
Table table = TEST_UTIL.createTable(
TableName.valueOf(name.getMethodName()), new byte[][] { FAMILY },
1, new byte[] { 0x00 }, new byte[] { (byte) 0xff }, 255);
Put put = new Put(ROW);
put.addColumn(FAMILY, QUALIFIER, VALUE);
Get get = new Get(ROW);
boolean exist = table.exists(get);
assertFalse(exist);
table.put(put);
exist = table.exists(get);
assertTrue(exist);
}
代码示例来源:origin: apache/hbase
@Test
public void testHTableExistsMethodSingleRegionMultipleGets() throws Exception {
Table table = TEST_UTIL.createTable(TableName.valueOf(
name.getMethodName()), new byte[][] { FAMILY });
Put put = new Put(ROW);
put.addColumn(FAMILY, QUALIFIER, VALUE);
table.put(put);
List<Get> gets = new ArrayList<>();
gets.add(new Get(ROW));
gets.add(new Get(ANOTHERROW));
boolean[] results = table.exists(gets);
assertTrue(results[0]);
assertFalse(results[1]);
}
代码示例来源:origin: apache/hbase
@Test
public void testHTableExistsMethodSingleRegionSingleGet() throws Exception {
// Test with a single region table.
Table table = TEST_UTIL.createTable(
TableName.valueOf(name.getMethodName()),
new byte[][] { FAMILY });
Put put = new Put(ROW);
put.addColumn(FAMILY, QUALIFIER, VALUE);
Get get = new Get(ROW);
boolean exist = table.exists(get);
assertFalse(exist);
table.put(put);
exist = table.exists(get);
assertTrue(exist);
}
代码示例来源:origin: apache/hbase
try {
table.exists(new Get(Bytes.toBytes("abc")));
} catch (SocketTimeoutException e) {
代码示例来源:origin: apache/hbase
try {
table.exists(new Get(Bytes.toBytes("abc")));
} catch (SocketTimeoutException e) {
代码示例来源:origin: apache/hbase
@Test
public void testBatchWithDelete() throws Exception {
LOG.info("test=testBatchWithDelete");
Table table = UTIL.getConnection().getTable(TEST_TABLE);
// Load some data
List<Put> puts = constructPutRequests();
Object[] results = new Object[puts.size()];
table.batch(puts, results);
validateSizeAndEmpty(results, KEYS.length);
// Deletes
List<Row> deletes = new ArrayList<>();
for (int i = 0; i < KEYS.length; i++) {
Delete delete = new Delete(KEYS[i]);
delete.addFamily(BYTES_FAMILY);
deletes.add(delete);
}
results= new Object[deletes.size()];
table.batch(deletes, results);
validateSizeAndEmpty(results, KEYS.length);
// Get to make sure ...
for (byte[] k : KEYS) {
Get get = new Get(k);
get.addColumn(BYTES_FAMILY, QUALIFIER);
Assert.assertFalse(table.exists(get));
}
table.close();
}
代码示例来源:origin: apache/hbase
@Test
public void testHTableDeleteWithList() throws Exception {
LOG.info("test=testHTableDeleteWithList");
Table table = UTIL.getConnection().getTable(TEST_TABLE);
// Load some data
List<Put> puts = constructPutRequests();
Object[] results = new Object[puts.size()];
table.batch(puts, results);
validateSizeAndEmpty(results, KEYS.length);
// Deletes
ArrayList<Delete> deletes = new ArrayList<>();
for (int i = 0; i < KEYS.length; i++) {
Delete delete = new Delete(KEYS[i]);
delete.addFamily(BYTES_FAMILY);
deletes.add(delete);
}
table.delete(deletes);
Assert.assertTrue(deletes.isEmpty());
// Get to make sure ...
for (byte[] k : KEYS) {
Get get = new Get(k);
get.addColumn(BYTES_FAMILY, QUALIFIER);
Assert.assertFalse(table.exists(get));
}
table.close();
}
代码示例来源:origin: apache/hbase
@Test
public void testTableExistsGetThrottle() throws Exception {
final Admin admin = TEST_UTIL.getAdmin();
// Add throttle quota
admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0],
ThrottleType.REQUEST_NUMBER, 100, TimeUnit.MINUTES));
triggerTableCacheRefresh(false, TABLE_NAMES[0]);
Table table = TEST_UTIL.getConnection().getTable(TABLE_NAMES[0]);
// An exists call when having throttle quota
table.exists(new Get(Bytes.toBytes("abc")));
admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0]));
triggerTableCacheRefresh(true, TABLE_NAMES[0]);
}
代码示例来源:origin: apache/hbase
@Test
public void testHTableExistsBeforeGet() throws Exception {
Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()),
new byte[][] { FAMILY });
try {
Put put = new Put(ROW);
put.addColumn(FAMILY, QUALIFIER, VALUE);
table.put(put);
Get get = new Get(ROW);
boolean exist = table.exists(get);
assertEquals(true, exist);
Result result = table.get(get);
assertEquals(false, result.isEmpty());
assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER)));
} finally {
table.close();
}
}
代码示例来源:origin: apache/hbase
assertTrue(table.exists(g));
代码示例来源:origin: apache/hbase
@Test
public void testDeleteRowForDeletedRegion() throws IOException, ReplicationException {
TableName tableName = TableName.valueOf(name.getMethodName());
RegionInfo region = RegionInfoBuilder.newBuilder(tableName).build();
addBarrier(region, 40, 50, 60);
fillCatalogFamily(region);
String peerId = "1";
ReplicationQueueStorage queueStorage = create(59L);
@SuppressWarnings("unchecked")
ReplicationPeerManager peerManager = create(queueStorage, Lists.newArrayList(peerId));
ReplicationBarrierCleaner cleaner = create(peerManager);
// we have something in catalog family, so only delete 40
cleaner.chore();
assertArrayEquals(new long[] { 50, 60 },
MetaTableAccessor.getReplicationBarrier(UTIL.getConnection(), region.getRegionName()));
verify(queueStorage, never()).removeLastSequenceIds(anyString(), anyList());
// No catalog family, then we should remove the whole row
clearCatalogFamily(region);
cleaner.chore();
try (Table table = UTIL.getConnection().getTable(TableName.META_TABLE_NAME)) {
assertFalse(table
.exists(new Get(region.getRegionName()).addFamily(HConstants.REPLICATION_BARRIER_FAMILY)));
}
verify(queueStorage, times(1)).removeLastSequenceIds(peerId,
Arrays.asList(region.getEncodedName()));
}
代码示例来源:origin: apache/hbase
assertEquals(0, Bytes.toInt(table.get(new Get(Bytes.toBytes(0))).getValue(CF, CQ)));
assertFalse(table.exists(new Get(Bytes.toBytes(1))));
table.exists(new Get(Bytes.toBytes(0)));
} catch (DoNotRetryIOException | RetriesExhaustedException e) {
代码示例来源:origin: apache/hbase
table.delete(delete);
util.flush(tableName);
assertFalse(table.exists(new Get(Bytes.toBytes(refSFCount-1))));
table.exists(new Get(Bytes.toBytes(refSFCount-1))));
内容来源于网络,如有侵权,请联系作者删除!