本文整理了Java中org.apache.hadoop.hbase.client.Table
类的一些代码示例,展示了Table
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table
类的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Table
类名称:Table
[英]Used to communicate with a single HBase table. Obtain an instance from a Connection and call #close() afterwards.
Table can be used to get, put, delete or scan data from a table.
[中]用于与单个HBase表通信。从连接中获取一个实例,然后调用#close()。
表可用于从表中获取、放置、删除或扫描数据。
代码示例来源:origin: thinkaurelius/titan
@Override
public ResultScanner getScanner(Scan filter) throws IOException
{
return table.getScanner(filter);
}
代码示例来源:origin: apache/hbase
@Override
public Object run() throws Exception {
try(Connection conn = ConnectionFactory.createConnection(conf);
Table t = conn.getTable(TEST_TABLE)) {
return t.get(new Get(TEST_ROW));
}
}
};
代码示例来源:origin: apache/hbase
@Override
public void workDone() throws IOException {
try {
table.close();
} finally {
connection.close();
}
}
代码示例来源:origin: apache/hbase
/**
* Invokes Table#delete to delete test data (i.e. the row)
*
* @param table Standard Table object
* @throws IOException If IO problem is encountered
*/
static void deleteRow(final Table table) throws IOException {
System.out.println("Deleting row [" + Bytes.toString(MY_ROW_ID)
+ "] from Table ["
+ table.getName().getNameAsString() + "].");
table.delete(new Delete(MY_ROW_ID));
}
代码示例来源:origin: apache/hbase
@Override
protected void closeHTable() {
if (table != null) {
try {
table.close();
} catch (Exception e) {
LOG.error("Error in closing the table "+table.getName(), e);
}
}
}
代码示例来源:origin: apache/hbase
@Override
public Object run() throws Exception {
Put p = new Put(TEST_ROW);
p.addColumn(family1, qualifier, Bytes.toBytes("v1"));
try (Connection conn = ConnectionFactory.createConnection(conf);
Table t = conn.getTable(tableName)) {
t.put(p);
}
return null;
}
};
代码示例来源:origin: apache/hbase
/**
* Test read only tables
* @throws Exception
*/
@Test
public void testReadOnlyTable() throws Exception {
final TableName name = TableName.valueOf(this.name.getMethodName());
Table table = TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY);
byte[] value = Bytes.toBytes("somedata");
// This used to use an empty row... That must have been a bug
Put put = new Put(value);
put.addColumn(HConstants.CATALOG_FAMILY, HConstants.CATALOG_FAMILY, value);
table.put(put);
table.close();
}
代码示例来源:origin: apache/hbase
protected final void write(HBaseTestingUtility util, int start, int end) throws IOException {
try (Table table = util.getConnection().getTable(TABLE_NAME)) {
for (int i = start; i < end; i++) {
table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
}
}
}
代码示例来源:origin: apache/hbase
private static final void createTable(HTableDescriptor desc) throws Exception {
Admin admin = TEST_UTIL.getAdmin();
admin.createTable(desc, new byte[][]{ROWS[rowSeperator1], ROWS[rowSeperator2]});
TEST_UTIL.waitUntilAllRegionsAssigned(desc.getTableName());
Table table = TEST_UTIL.getConnection().getTable(desc.getTableName());
try {
for (int i = 0; i < ROWSIZE; i++) {
Put put = new Put(ROWS[i]);
put.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(i));
table.put(put);
}
} finally {
table.close();
}
}
代码示例来源:origin: apache/hbase
@Test
public void testFlush() throws IOException {
byte[] row = Bytes.toBytes("row");
byte[] cf = Bytes.toBytes("cf");
byte[] cq = Bytes.toBytes("cq");
byte[] value = Bytes.toBytes("value");
TableName name = TableName.valueOf(getClass().getSimpleName());
Table t = util.createTable(name, cf);
t.put(new Put(row).addColumn(cf, cq, value));
util.getAdmin().flush(name);
assertArrayEquals(value, t.get(new Get(row)).getValue(cf, cq));
}
}
代码示例来源:origin: apache/hbase
@Test
public void testBatchWithRowMutation() throws Exception {
LOG.info("Starting testBatchWithRowMutation");
final TableName TABLENAME = TableName.valueOf("testBatchWithRowMutation");
try (Table t = TEST_UTIL.createTable(TABLENAME, FAMILY)) {
byte [][] QUALIFIERS = new byte [][] {
Bytes.toBytes("a"), Bytes.toBytes("b")
};
new Put(ROW).addColumn(FAMILY, QUALIFIERS[0], VALUE)));
Object[] batchResult = new Object[1];
t.batch(Arrays.asList(arm), batchResult);
Result r = t.get(g);
assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[0])));
new Put(ROW).addColumn(FAMILY, QUALIFIERS[1], VALUE),
new Delete(ROW).addColumns(FAMILY, QUALIFIERS[0])));
t.batch(Arrays.asList(arm), batchResult);
r = t.get(g);
assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[1])));
assertNull(r.getValue(FAMILY, QUALIFIERS[0]));
arm = RowMutations.of(Collections.singletonList(
new Put(ROW).addColumn(new byte[]{'b', 'o', 'g', 'u', 's'}, QUALIFIERS[0], VALUE)));
t.batch(Arrays.asList(arm), batchResult);
fail("Expected RetriesExhaustedWithDetailsException with NoSuchColumnFamilyException");
} catch(RetriesExhaustedWithDetailsException e) {
代码示例来源: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
@Test(expected=RetriesExhaustedException.class)
public void testSocketClosed() throws IOException, InterruptedException {
TableName tableName = TableName.valueOf(name.getMethodName());
UTIL.createTable(tableName, fam1).close();
Configuration conf = new Configuration(UTIL.getConfiguration());
conf.set(RpcClientFactory.CUSTOM_RPC_CLIENT_IMPL_CONF_KEY,
MyRpcClientImpl.class.getName());
conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf(name.getMethodName()));
table.get(new Get(Bytes.toBytes("asd")));
connection.close();
for (Socket socket : MyRpcClientImpl.savedSockets) {
assertTrue("Socket + " + socket + " is not closed", socket.isClosed());
}
}
}
代码示例来源:origin: apache/hbase
@Test
public void testBatchWithIncrementAndAppend() throws Exception {
LOG.info("test=testBatchWithIncrementAndAppend");
final byte[] QUAL1 = Bytes.toBytes("qual1");
final byte[] QUAL2 = Bytes.toBytes("qual2");
final byte[] QUAL3 = Bytes.toBytes("qual3");
final byte[] QUAL4 = Bytes.toBytes("qual4");
Table table = UTIL.getConnection().getTable(TEST_TABLE);
Delete d = new Delete(ONE_ROW);
table.delete(d);
Put put = new Put(ONE_ROW);
put.addColumn(BYTES_FAMILY, QUAL1, Bytes.toBytes("abc"));
put.addColumn(BYTES_FAMILY, QUAL2, Bytes.toBytes(1L));
table.put(put);
table.batch(actions, multiRes);
validateResult(multiRes[1], QUAL1, Bytes.toBytes("abcdef"));
validateResult(multiRes[1], QUAL4, Bytes.toBytes("xyz"));
validateResult(multiRes[0], QUAL2, Bytes.toBytes(2L));
validateResult(multiRes[0], QUAL3, Bytes.toBytes(1L));
table.close();
代码示例来源:origin: apache/hbase
/**
* For HADOOP-2579
* @throws IOException
*/
@Test (expected=TableNotFoundException.class)
public void testTableNotFoundExceptionWithoutAnyTables() throws IOException {
TableName tableName = TableName
.valueOf("testTableNotFoundExceptionWithoutAnyTables");
Table ht = TEST_UTIL.getConnection().getTable(tableName);
ht.get(new Get(Bytes.toBytes("e")));
}
代码示例来源:origin: apache/hbase
@Test
public void testDisabledWAL() throws Exception {
LOG.info("Writing data to table " + tableName);
Put p = new Put(Bytes.toBytes("row"));
p.addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("val"));
table.put(p);
LOG.info("Flushing table " + tableName);
TEST_UTIL.flush(tableName);
LOG.info("Getting data from table " + tableName);
Get get = new Get(Bytes.toBytes("row"));
Result result = table.get(get);
assertNotNull(result.getValue(fam, Bytes.toBytes("qual")));
}
}
代码示例来源:origin: apache/hbase
@Test
public void testIncrement() throws IOException {
try (Table t = TEST_UTIL.getConnection().getTable(TABLE_NAME)) {
Put put = new Put(ROW);
put.addColumn(FAMILY, QUAL, VALUE);
t.put(put);
assertRowAndValue(t.get(new Get(ROW)), ROW, VALUE);
Increment inc = new Increment(ROW);
inc.addColumn(FAMILY, QUAL, 99);
assertRowAndValue(t.increment(inc), ROW, FIXED_VALUE);
assertRowAndValue(t.get(new Get(ROW)), ROW, Bytes.toBytes(199L));
}
}
代码示例来源:origin: apache/hbase
@Test
public void testBatchAppendWithReturnResultFalse() throws Exception {
LOG.info("Starting testBatchAppendWithReturnResultFalse");
final TableName tableName = TableName.valueOf(name.getMethodName());
Table table = TEST_UTIL.createTable(tableName, FAMILY);
Append append1 = new Append(Bytes.toBytes("row1"));
append1.setReturnResults(false);
append1.addColumn(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value1"));
Append append2 = new Append(Bytes.toBytes("row1"));
append2.setReturnResults(false);
append2.addColumn(FAMILY, Bytes.toBytes("f1"), Bytes.toBytes("value2"));
List<Append> appends = new ArrayList<>();
appends.add(append1);
appends.add(append2);
Object[] results = new Object[2];
table.batch(appends, results);
assertTrue(results.length == 2);
for(Object r : results) {
Result result = (Result)r;
assertTrue(result.isEmpty());
}
table.close();
}
代码示例来源:origin: apache/hbase
public int testGet(final RegionInfo hri, final int nrows) throws IOException {
int nresults = 0;
final Table table = UTIL.getConnection().getTable(hri.getTable());
for (int i = 0; i < nrows; ++i) {
final byte[] row = Bytes.add(hri.getStartKey(), Bytes.toBytes(i));
final Result result = table.get(new Get(row));
if (result != null && !result.isEmpty() &&
Bytes.equals(row, result.getValue(FAMILY, null))) {
nresults++;
}
}
return nresults;
}
}
代码示例来源:origin: apache/hbase
@Test
public void testHTableWithLargeBatch() throws Exception {
Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()),
new byte[][] { FAMILY });
int sixtyFourK = 64 * 1024;
try {
List actions = new ArrayList();
Object[] results = new Object[(sixtyFourK + 1) * 2];
for (int i = 0; i < sixtyFourK + 1; i ++) {
Put put1 = new Put(ROW);
put1.addColumn(FAMILY, QUALIFIER, VALUE);
actions.add(put1);
Put put2 = new Put(ANOTHERROW);
put2.addColumn(FAMILY, QUALIFIER, VALUE);
actions.add(put2);
}
table.batch(actions, results);
} finally {
table.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!