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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

@Override
public TResult append(ByteBuffer table, TAppend append) throws TIOError, TException {
 checkReadOnlyMode();
 Table htable = getTable(table);
 try {
  return resultFromHBase(htable.append(appendFromThrift(append)));
 } catch (IOException e) {
  throw getTIOError(e);
 } finally {
  closeTable(htable);
 }
}

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

@Override
public List<TCell> append(TAppend tappend) throws IOError, TException {
 if (tappend.getRow().length == 0 || tappend.getTable().length == 0) {
  throw new TException("Must supply a table and a row key; can't append");
 }
 Table table = null;
 try {
  table = getTable(tappend.getTable());
  Append append = ThriftUtilities.appendFromThrift(tappend);
  Result result = table.append(append);
  return ThriftUtilities.cellFromHBase(result.rawCells());
 } catch (IOException e) {
  LOG.warn(e.getMessage(), e);
  throw getIOError(e);
 } finally{
  closeTable(table);
 }
}

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

@Override
 public Void run() throws Exception {
  try (Connection connection = ConnectionFactory.createConnection(conf);
     Table table = connection.getTable(tableName)) {
   Append append = new Append(row1);
   append.addColumn(fam, qual, Bytes.toBytes("b"));
   table.append(append);
  }
  return null;
 }
};

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

@Override
 public Object run() throws Exception {
  byte[] row = TEST_ROW;
  byte[] qualifier = TEST_QUALIFIER;
  Put put = new Put(row);
  put.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(1));
  Append append = new Append(row);
  append.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(2));
  try(Connection conn = ConnectionFactory.createConnection(conf);
    Table t = conn.getTable(TEST_TABLE)) {
   t.put(put);
   t.append(append);
  }
  return null;
 }
};

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

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

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

@Override
 public Void run() throws Exception {
  try (Connection connection = ConnectionFactory.createConnection(conf);
     Table table = connection.getTable(tableName)) {
   Append append = new Append(row1);
   append.addColumn(fam, qual, Bytes.toBytes("c"));
   append.setCellVisibility(new CellVisibility(PUBLIC));
   table.append(append);
   Assert.fail("Testcase should fail with AccesDeniedException");
  } catch (Throwable t) {
   assertTrue(t.getMessage().contains("AccessDeniedException"));
  }
  return null;
 }
};

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

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

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

@Override
 public Object run() throws Exception {
  try {
   if (table == null) {
    table = connection.getTable(tableName);
   }
   if (m instanceof Increment) {
    table.increment((Increment) m);
   } else if (m instanceof Append) {
    table.append((Append) m);
   } else if (m instanceof Put) {
    table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenPut((Put) m);
   } else if (m instanceof Delete) {
    table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenDelete((Delete) m);
   } else {
    throw new IllegalArgumentException("unsupported mutation "
      + m.getClass().getSimpleName());
   }
   totalOpTimeMs.addAndGet(System.currentTimeMillis() - start);
  } catch (IOException e) {
   recordFailure(m, keyBase, start, e);
  }
  return null;
 }
}

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

@Test
public void testAppend() 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);
  Append append = new Append(ROW);
  append.addColumn(FAMILY, QUAL, FIXED_VALUE);
  assertRowAndValue(t.append(append), ROW, FIXED_VALUE);
  assertRowAndValue(t.get(new Get(ROW)), ROW, Bytes.add(VALUE, FIXED_VALUE));
 }
}

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

@Test
public void testAppend() throws Exception {
 LOG.info("Starting testAppend");
 final TableName tableName = TableName.valueOf(name.getMethodName());
 Table t = TEST_UTIL.createTable(tableName, FAMILY);
 byte[] v1 = Bytes.toBytes("42");
 byte[] v2 = Bytes.toBytes("23");
 byte [][] QUALIFIERS = new byte [][] {
   Bytes.toBytes("b"), Bytes.toBytes("a"), Bytes.toBytes("c")
 };
 Append a = new Append(ROW);
 a.addColumn(FAMILY, QUALIFIERS[0], v1);
 a.addColumn(FAMILY, QUALIFIERS[1], v2);
 a.setReturnResults(false);
 assertEmptyResult(t.append(a));
 a = new Append(ROW);
 a.addColumn(FAMILY, QUALIFIERS[0], v2);
 a.addColumn(FAMILY, QUALIFIERS[1], v1);
 a.addColumn(FAMILY, QUALIFIERS[2], v2);
 Result r = t.append(a);
 assertEquals(0, Bytes.compareTo(Bytes.add(v1, v2), r.getValue(FAMILY, QUALIFIERS[0])));
 assertEquals(0, Bytes.compareTo(Bytes.add(v2, v1), r.getValue(FAMILY, QUALIFIERS[1])));
 // QUALIFIERS[2] previously not exist, verify both value and timestamp are correct
 assertEquals(0, Bytes.compareTo(v2, r.getValue(FAMILY, QUALIFIERS[2])));
 assertEquals(r.getColumnLatestCell(FAMILY, QUALIFIERS[0]).getTimestamp(),
   r.getColumnLatestCell(FAMILY, QUALIFIERS[2]).getTimestamp());
}
private List<Result> doAppend(final boolean walUsed) throws IOException {

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

@Test
public void testAppendHook() throws IOException {
 final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
 Table table = util.createTable(tableName, new byte[][] { A, B, C });
 try {
  Append app = new Append(Bytes.toBytes(0));
  app.addColumn(A, A, A);
  verifyMethodResult(SimpleRegionObserver.class,
   new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock" }, tableName,
   new Boolean[] { false, false, false });
  table.append(app);
  verifyMethodResult(SimpleRegionObserver.class,
   new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock" }, tableName,
   new Boolean[] { true, true, true });
 } finally {
  util.deleteTable(tableName);
  table.close();
 }
}

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

@Test
public void testLabelsWithAppend() throws Throwable {
 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
 try (Table table = TEST_UTIL.createTable(tableName, fam)) {
  byte[] row1 = Bytes.toBytes("row1");
  byte[] val = Bytes.toBytes("a");
  Put put = new Put(row1);
  put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, val);
  put.setCellVisibility(new CellVisibility(SECRET + " & " + CONFIDENTIAL));
  table.put(put);
  Get get = new Get(row1);
  get.setAuthorizations(new Authorizations(SECRET));
  Result result = table.get(get);
  assertTrue(result.isEmpty());
  Append append = new Append(row1);
  append.addColumn(fam, qual, Bytes.toBytes("b"));
  table.append(append);
  result = table.get(get);
  assertTrue(result.isEmpty());
  append = new Append(row1);
  append.addColumn(fam, qual, Bytes.toBytes("c"));
  append.setCellVisibility(new CellVisibility(SECRET));
  table.append(append);
  result = table.get(get);
  assertTrue(!result.isEmpty());
 }
}

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

@Test
public void testChangeCellWithDifferntColumnFamily() throws Exception {
 TableName tableName = TableName.valueOf(name.getMethodName());
 createTableWithCoprocessor(tableName,
  ChangeCellWithDifferntColumnFamilyObserver.class.getName());
 try (Table table = connection.getTable(tableName)) {
  Increment increment = new Increment(ROW).addColumn(CF1_BYTES, CQ1, 1);
  table.increment(increment);
  Get get = new Get(ROW).addColumn(CF2_BYTES, CQ1);
  Result result = table.get(get);
  assertEquals(1, result.size());
  assertEquals(1, Bytes.toLong(result.getValue(CF2_BYTES, CQ1)));
  Append append = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE);
  table.append(append);
  get = new Get(ROW).addColumn(CF2_BYTES, CQ2);
  result = table.get(get);
  assertEquals(1, result.size());
  assertTrue(Bytes.equals(VALUE, result.getValue(CF2_BYTES, CQ2)));
 }
}

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

@Test
public void testChangeCellWithNotExistColumnFamily() throws Exception {
 TableName tableName = TableName.valueOf(name.getMethodName());
 createTableWithCoprocessor(tableName,
  ChangeCellWithNotExistColumnFamilyObserver.class.getName());
 try (Table table = connection.getTable(tableName)) {
  try {
   Increment increment = new Increment(ROW).addColumn(CF1_BYTES, CQ1, 1);
   table.increment(increment);
   fail("should throw NoSuchColumnFamilyException");
  } catch (Exception e) {
   assertTrue(e instanceof NoSuchColumnFamilyException);
  }
  try {
   Append append = new Append(ROW).addColumn(CF1_BYTES, CQ2, VALUE);
   table.append(append);
   fail("should throw NoSuchColumnFamilyException");
  } catch (Exception e) {
   assertTrue(e instanceof NoSuchColumnFamilyException);
  }
 }
}

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

@Test
 public void testAppendWithCustomTimestamp() throws IOException {
  TableName TABLENAME = TableName.valueOf(name.getMethodName());
  Table table = TEST_UTIL.createTable(TABLENAME, FAMILY);
  long timestamp = 999;
  Append append = new Append(ROW);
  append.add(CellUtil.createCell(ROW, FAMILY, QUALIFIER, timestamp, KeyValue.Type.Put.getCode(), Bytes.toBytes(100L)));
  Result r = table.append(append);
  assertEquals(1, r.size());
  assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  r = table.get(new Get(ROW));
  assertEquals(1, r.size());
  assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  r = table.append(append);
  assertEquals(1, r.size());
  assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
  r = table.get(new Get(ROW));
  assertEquals(1, r.size());
  assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
 }
}

相关文章