org.apache.hadoop.hbase.client.Table.append()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(226)

本文整理了Java中org.apache.hadoop.hbase.client.Table.append()方法的一些代码示例,展示了Table.append()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table.append()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Table
类名称:Table
方法名:append

Table.append介绍

[英]Appends values to one or more columns within a single row.

This operation does not appear atomic to readers. Appends are done under a single row lock, so write operations to a row are synchronized, but readers do not take row locks so get and scan operations can see this operation partially completed.
[中]将值追加到单行中的一列或多列。
在读者看来,此操作不是原子操作。追加是在单行锁下完成的,因此对行的写入操作是同步的,但读卡器不接受行锁,因此get和scan操作可以看到该操作部分完成。

代码示例

代码示例来源:origin: apache/hbase

  1. @Test(expected = DoNotRetryIOException.class)
  2. public void testAppendWithDoNotRetryIOException() throws Exception {
  3. tableDoNotRetry
  4. .append(new Append(Bytes.toBytes("row")).addColumn(CF, CQ, Bytes.toBytes("value")));
  5. }

代码示例来源:origin: apache/hbase

  1. private void testAppend(Append append) throws Exception {
  2. checkResult(table.append(append));
  3. List<Row> actions = Arrays.asList(append, append);
  4. Object[] results = new Object[actions.size()];
  5. table.batch(actions, results);
  6. checkResult(results);
  7. }

代码示例来源:origin: apache/hbase

  1. @Test(expected = InvalidMutationDurabilityException.class)
  2. public void testAppendToTableNeedReplicate() throws Exception {
  3. tableNeedReplicate.append(newAppendWithSkipWAL());
  4. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testAppendToTableNotReplicate() throws Exception {
  3. tableNotReplicate.append(newAppendWithSkipWAL());
  4. }

代码示例来源:origin: apache/hbase

  1. @Test(expected = RetriesExhaustedException.class)
  2. public void testAppendWithIOException() throws Exception {
  3. tableRetry.append(new Append(Bytes.toBytes("row")).addColumn(CF, CQ, Bytes.toBytes("value")));
  4. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public TResult append(ByteBuffer table, TAppend append) throws TIOError, TException {
  3. checkReadOnlyMode();
  4. Table htable = getTable(table);
  5. try {
  6. return resultFromHBase(htable.append(appendFromThrift(append)));
  7. } catch (IOException e) {
  8. throw getTIOError(e);
  9. } finally {
  10. closeTable(htable);
  11. }
  12. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public List<TCell> append(TAppend tappend) throws IOError, TException {
  3. if (tappend.getRow().length == 0 || tappend.getTable().length == 0) {
  4. throw new TException("Must supply a table and a row key; can't append");
  5. }
  6. Table table = null;
  7. try {
  8. table = getTable(tappend.getTable());
  9. Append append = ThriftUtilities.appendFromThrift(tappend);
  10. Result result = table.append(append);
  11. return ThriftUtilities.cellFromHBase(result.rawCells());
  12. } catch (IOException e) {
  13. LOG.warn(e.getMessage(), e);
  14. throw getIOError(e);
  15. } finally{
  16. closeTable(table);
  17. }
  18. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Void run() throws Exception {
  3. try (Connection connection = ConnectionFactory.createConnection(conf);
  4. Table table = connection.getTable(tableName)) {
  5. Append append = new Append(row1);
  6. append.addColumn(fam, qual, Bytes.toBytes("b"));
  7. table.append(append);
  8. }
  9. return null;
  10. }
  11. };

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Object run() throws Exception {
  3. byte[] row = TEST_ROW;
  4. byte[] qualifier = TEST_QUALIFIER;
  5. Put put = new Put(row);
  6. put.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(1));
  7. Append append = new Append(row);
  8. append.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(2));
  9. try(Connection conn = ConnectionFactory.createConnection(conf);
  10. Table t = conn.getTable(TEST_TABLE)) {
  11. t.put(put);
  12. t.append(append);
  13. }
  14. return null;
  15. }
  16. };

代码示例来源:origin: apache/hbase

  1. @Override
  2. boolean testRow(final int i) throws IOException {
  3. byte [] bytes = format(i);
  4. Append append = new Append(bytes);
  5. // unlike checkAndXXX tests, which make most sense to do on a single value,
  6. // if multiple families are specified for an append test we assume it is
  7. // meant to raise the work factor
  8. for (int family = 0; family < opts.families; family++) {
  9. byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family);
  10. append.addColumn(familyName, getQualifier(), bytes);
  11. }
  12. updateValueSize(this.table.append(append));
  13. return true;
  14. }
  15. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Void run() throws Exception {
  3. try (Connection connection = ConnectionFactory.createConnection(conf);
  4. Table table = connection.getTable(tableName)) {
  5. Append append = new Append(row1);
  6. append.addColumn(fam, qual, Bytes.toBytes("c"));
  7. append.setCellVisibility(new CellVisibility(PUBLIC));
  8. table.append(append);
  9. Assert.fail("Testcase should fail with AccesDeniedException");
  10. } catch (Throwable t) {
  11. assertTrue(t.getMessage().contains("AccessDeniedException"));
  12. }
  13. return null;
  14. }
  15. };

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testAppend() throws Exception {
  3. doNPuts(1, false);
  4. for(int count = 0; count< 73; count++) {
  5. Append append = new Append(row);
  6. append.addColumn(cf, qualifier, Bytes.toBytes(",Test"));
  7. table.append(append);
  8. }
  9. metricsRegionServer.getRegionServerWrapper().forceRecompute();
  10. assertCounter("appendNumOps", 73);
  11. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public Object run() throws Exception {
  3. try {
  4. if (table == null) {
  5. table = connection.getTable(tableName);
  6. }
  7. if (m instanceof Increment) {
  8. table.increment((Increment) m);
  9. } else if (m instanceof Append) {
  10. table.append((Append) m);
  11. } else if (m instanceof Put) {
  12. table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenPut((Put) m);
  13. } else if (m instanceof Delete) {
  14. table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenDelete((Delete) m);
  15. } else {
  16. throw new IllegalArgumentException("unsupported mutation "
  17. + m.getClass().getSimpleName());
  18. }
  19. totalOpTimeMs.addAndGet(System.currentTimeMillis() - start);
  20. } catch (IOException e) {
  21. recordFailure(m, keyBase, start, e);
  22. }
  23. return null;
  24. }
  25. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testAppend() throws IOException {
  3. try (Table t = TEST_UTIL.getConnection().getTable(TABLE_NAME)) {
  4. Put put = new Put(ROW);
  5. put.addColumn(FAMILY, QUAL, VALUE);
  6. t.put(put);
  7. assertRowAndValue(t.get(new Get(ROW)), ROW, VALUE);
  8. Append append = new Append(ROW);
  9. append.addColumn(FAMILY, QUAL, FIXED_VALUE);
  10. assertRowAndValue(t.append(append), ROW, FIXED_VALUE);
  11. assertRowAndValue(t.get(new Get(ROW)), ROW, Bytes.add(VALUE, FIXED_VALUE));
  12. }
  13. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testAppend() throws Exception {
  3. LOG.info("Starting testAppend");
  4. final TableName tableName = TableName.valueOf(name.getMethodName());
  5. Table t = TEST_UTIL.createTable(tableName, FAMILY);
  6. byte[] v1 = Bytes.toBytes("42");
  7. byte[] v2 = Bytes.toBytes("23");
  8. byte [][] QUALIFIERS = new byte [][] {
  9. Bytes.toBytes("b"), Bytes.toBytes("a"), Bytes.toBytes("c")
  10. };
  11. Append a = new Append(ROW);
  12. a.addColumn(FAMILY, QUALIFIERS[0], v1);
  13. a.addColumn(FAMILY, QUALIFIERS[1], v2);
  14. a.setReturnResults(false);
  15. assertEmptyResult(t.append(a));
  16. a = new Append(ROW);
  17. a.addColumn(FAMILY, QUALIFIERS[0], v2);
  18. a.addColumn(FAMILY, QUALIFIERS[1], v1);
  19. a.addColumn(FAMILY, QUALIFIERS[2], v2);
  20. Result r = t.append(a);
  21. assertEquals(0, Bytes.compareTo(Bytes.add(v1, v2), r.getValue(FAMILY, QUALIFIERS[0])));
  22. assertEquals(0, Bytes.compareTo(Bytes.add(v2, v1), r.getValue(FAMILY, QUALIFIERS[1])));
  23. // QUALIFIERS[2] previously not exist, verify both value and timestamp are correct
  24. assertEquals(0, Bytes.compareTo(v2, r.getValue(FAMILY, QUALIFIERS[2])));
  25. assertEquals(r.getColumnLatestCell(FAMILY, QUALIFIERS[0]).getTimestamp(),
  26. r.getColumnLatestCell(FAMILY, QUALIFIERS[2]).getTimestamp());
  27. }
  28. private List<Result> doAppend(final boolean walUsed) throws IOException {

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testAppendHook() throws IOException {
  3. final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
  4. Table table = util.createTable(tableName, new byte[][] { A, B, C });
  5. try {
  6. Append app = new Append(Bytes.toBytes(0));
  7. app.addColumn(A, A, A);
  8. verifyMethodResult(SimpleRegionObserver.class,
  9. new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock" }, tableName,
  10. new Boolean[] { false, false, false });
  11. table.append(app);
  12. verifyMethodResult(SimpleRegionObserver.class,
  13. new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock" }, tableName,
  14. new Boolean[] { true, true, true });
  15. } finally {
  16. util.deleteTable(tableName);
  17. table.close();
  18. }
  19. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testLabelsWithAppend() throws Throwable {
  3. TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  4. try (Table table = TEST_UTIL.createTable(tableName, fam)) {
  5. byte[] row1 = Bytes.toBytes("row1");
  6. byte[] val = Bytes.toBytes("a");
  7. Put put = new Put(row1);
  8. put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, val);
  9. put.setCellVisibility(new CellVisibility(SECRET + " & " + CONFIDENTIAL));
  10. table.put(put);
  11. Get get = new Get(row1);
  12. get.setAuthorizations(new Authorizations(SECRET));
  13. Result result = table.get(get);
  14. assertTrue(result.isEmpty());
  15. Append append = new Append(row1);
  16. append.addColumn(fam, qual, Bytes.toBytes("b"));
  17. table.append(append);
  18. result = table.get(get);
  19. assertTrue(result.isEmpty());
  20. append = new Append(row1);
  21. append.addColumn(fam, qual, Bytes.toBytes("c"));
  22. append.setCellVisibility(new CellVisibility(SECRET));
  23. table.append(append);
  24. result = table.get(get);
  25. assertTrue(!result.isEmpty());
  26. }
  27. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testChangeCellWithDifferntColumnFamily() throws Exception {
  3. TableName tableName = TableName.valueOf(name.getMethodName());
  4. createTableWithCoprocessor(tableName,
  5. ChangeCellWithDifferntColumnFamilyObserver.class.getName());
  6. try (Table table = connection.getTable(tableName)) {
  7. Increment increment = new Increment(ROW).addColumn(CF1_BYTES, CQ1, 1);
  8. table.increment(increment);
  9. Get get = new Get(ROW).addColumn(CF2_BYTES, CQ1);
  10. Result result = table.get(get);
  11. assertEquals(1, result.size());
  12. assertEquals(1, Bytes.toLong(result.getValue(CF2_BYTES, CQ1)));
  13. Append append = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE);
  14. table.append(append);
  15. get = new Get(ROW).addColumn(CF2_BYTES, CQ2);
  16. result = table.get(get);
  17. assertEquals(1, result.size());
  18. assertTrue(Bytes.equals(VALUE, result.getValue(CF2_BYTES, CQ2)));
  19. }
  20. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testChangeCellWithNotExistColumnFamily() throws Exception {
  3. TableName tableName = TableName.valueOf(name.getMethodName());
  4. createTableWithCoprocessor(tableName,
  5. ChangeCellWithNotExistColumnFamilyObserver.class.getName());
  6. try (Table table = connection.getTable(tableName)) {
  7. try {
  8. Increment increment = new Increment(ROW).addColumn(CF1_BYTES, CQ1, 1);
  9. table.increment(increment);
  10. fail("should throw NoSuchColumnFamilyException");
  11. } catch (Exception e) {
  12. assertTrue(e instanceof NoSuchColumnFamilyException);
  13. }
  14. try {
  15. Append append = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE);
  16. table.append(append);
  17. fail("should throw NoSuchColumnFamilyException");
  18. } catch (Exception e) {
  19. assertTrue(e instanceof NoSuchColumnFamilyException);
  20. }
  21. }
  22. }

代码示例来源:origin: apache/hbase

  1. @Test
  2. public void testAppendWithCustomTimestamp() throws IOException {
  3. TableName TABLENAME = TableName.valueOf(name.getMethodName());
  4. Table table = TEST_UTIL.createTable(TABLENAME, FAMILY);
  5. long timestamp = 999;
  6. Append append = new Append(ROW);
  7. append.add(CellUtil.createCell(ROW, FAMILY, QUALIFIER, timestamp, KeyValue.Type.Put.getCode(), Bytes.toBytes(100L)));
  8. Result r = table.append(append);
  9. assertEquals(1, r.size());
  10. assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  11. r = table.get(new Get(ROW));
  12. assertEquals(1, r.size());
  13. assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  14. r = table.append(append);
  15. assertEquals(1, r.size());
  16. assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
  17. r = table.get(new Get(ROW));
  18. assertEquals(1, r.size());
  19. assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
  20. }
  21. }

相关文章