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

x33g5p2x  于2022-01-21 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(157)

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

Increment.addColumn介绍

[英]Increment the column from the specific family with the specified qualifier by the specified amount.

Overrides previous calls to addColumn for this family and qualifier.
[中]将具有指定限定符的特定族中的列按指定数量递增。
覆盖以前对此族和限定符的addColumn调用。

代码示例

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

@Override
public List<Increment> getIncrements() {
 List<Increment> incs = new LinkedList<Increment>();
 if (incCol != null) {
  Increment inc = new Increment(incrementRow);
  inc.addColumn(cf, incCol, 1);
  incs.add(inc);
 }
 return incs;
}

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

@Override
public List<Increment> getIncrements() {
 List<Increment> incs = new LinkedList<>();
 if (incCol != null) {
  Increment inc = new Increment(incrementRow);
  inc.addColumn(cf, incCol, 1);
  incs.add(inc);
 }
 return incs;
}

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

private static void increment(int sleepSteps) throws IOException {
 for (long i = 1; i <= UPPER; i++) {
  TABLE.increment(new Increment(ROW).addColumn(FAMILY, CQ1, i).addColumn(FAMILY, CQ2, 2 * i));
  if (sleepSteps > 0 && i % sleepSteps == 0) {
   try {
    Thread.sleep(10);
   } catch (InterruptedException e) {
   }
  }
 }
}

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

CrossRowCellIncrementer(final int i, final int count, final HRegion region, final int range) {
 super("" + i);
 setDaemon(true);
 this.count = count;
 this.region = region;
 this.increments = new Increment[range];
 for (int ii = 0; ii < range; ii++) {
  this.increments[ii] = new Increment(Bytes.toBytes(i));
  this.increments[ii].addColumn(INCREMENT_BYTES, INCREMENT_BYTES, 1);
 }
}

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

private Increment newIncrementWithSkipWAL() {
 Increment increment = new Increment(Bytes.toBytes("row"));
 increment.addColumn(CF, CQ, 1);
 increment.setDurability(Durability.SKIP_WAL);
 return increment;
}

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

@Override
 protected void execute(Table table) throws IOException {
  table.increment(new Increment(FAM_NAM).addColumn(FAM_NAM, FAM_NAM, 1));
 }
}

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

/**
 * From a {@link TIncrement} create an {@link Increment}.
 * @param tincrement the Thrift version of an increment
 * @return an increment that the {@link TIncrement} represented.
 */
public static Increment incrementFromThrift(TIncrement tincrement) {
 Increment inc = new Increment(tincrement.getRow());
 byte[][] famAndQf = CellUtil.parseColumn(tincrement.getColumn());
 if (famAndQf.length != 2) {
  return null;
 }
 inc.addColumn(famAndQf[0], famAndQf[1], tincrement.getAmmount());
 return inc;
}

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

@Override
 public void run() {
  int count = 0;
  while (count < incCounter) {
   Increment inc = new Increment(incRow);
   inc.addColumn(family, qualifier, ONE);
   count++;
   try {
    region.increment(inc);
   } catch (IOException e) {
    LOG.info("Count=" + count + ", " + e);
    break;
   }
  }
 }
}

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

@Test
public void testNoInsertsWithIncrement() throws Exception {
 Increment i = new Increment(Bytes.toBytes("to_reject"));
 i.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("count"), 0);
 writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_INSERTS, i);
}

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

@Test
public void testNoWritesWithIncrement() throws Exception {
 Increment i = new Increment(Bytes.toBytes("to_reject"));
 i.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("count"), 0);
 writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_WRITES, i);
}

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

@Override
 public void run() {
  try {
   for (int i = 0; i < 100; i++) {
    byte[] row = Bytes.toBytes("incrementRow" + i);
    Increment inc = new Increment(row);
    inc.addColumn("cf".getBytes(), Bytes.toBytes(0), 1);
    // inc.setDurability(Durability.ASYNC_WAL);
    region.increment(inc);
    latch.countDown();
    Thread.sleep(10);
   }
  } catch (Throwable t) {
   LOG.warn("Error happend when Put: ", t);
  }
 }
}

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

/**
 * Atomically increments a column value. If the column value already exists and is not a
 * big-endian long, this could throw an exception. If the column value does not yet exist it is
 * initialized to <code>amount</code> and written to the specified column.
 * <p>
 * Setting durability to {@link Durability#SKIP_WAL} means that in a fail scenario you will lose
 * any increments that have not been flushed.
 * @param row The row that contains the cell to increment.
 * @param family The column family of the cell to increment.
 * @param qualifier The column qualifier of the cell to increment.
 * @param amount The amount to increment the cell with (or decrement, if the amount is negative).
 * @param durability The persistence guarantee for this increment.
 * @return The new value, post increment. The return value will be wrapped by a
 *         {@link CompletableFuture}.
 */
default CompletableFuture<Long> incrementColumnValue(byte[] row, byte[] family, byte[] qualifier,
  long amount, Durability durability) {
 Preconditions.checkNotNull(row, "row is null");
 Preconditions.checkNotNull(family, "family is null");
 return increment(
  new Increment(row).addColumn(family, qualifier, amount).setDurability(durability))
    .thenApply(r -> Bytes.toLong(r.getValue(family, qualifier)));
}

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

@Test(expected = DoNotRetryIOException.class)
public void testIncrementWithDoNotRetryIOException() throws Exception {
 tableDoNotRetry.increment(new Increment(Bytes.toBytes("row")).addColumn(CF, CQ, 1));
}

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

@Test(expected = RetriesExhaustedException.class)
public void testIncrementWithIOException() throws Exception {
 tableRetry.increment(new Increment(Bytes.toBytes("row")).addColumn(CF, CQ, 1));
}

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

@Test
public void testIncrement() throws Exception {
 testAppend(new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 10L));
 testAppend(new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 10L)
      .setReturnResults(false));
}

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

/**
 * See {@link #incrementColumnValue(byte[], byte[], byte[], long, Durability)}
 * <p>
 * The {@link Durability} is defaulted to {@link Durability#SYNC_WAL}.
 * @param row The row that contains the cell to increment.
 * @param family The column family of the cell to increment.
 * @param qualifier The column qualifier of the cell to increment.
 * @param amount The amount to increment the cell with (or decrement, if the
 * amount is negative).
 * @return The new value, post increment.
 * @throws IOException if a remote or network exception occurs.
 */
default long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount)
  throws IOException {
 Increment increment = new Increment(row).addColumn(family, qualifier, amount);
 Cell cell = increment(increment).getColumnLatestCell(family, qualifier);
 return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
}

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

@Override
 public Object run() throws Exception {
  Increment inc = new Increment(TEST_ROW);
  inc.addColumn(TEST_FAMILY, TEST_QUALIFIER, 1);
  try(Connection conn = ConnectionFactory.createConnection(conf);
    Table t = conn.getTable(TEST_TABLE)) {
   t.increment(inc);
  }
  return null;
 }
};

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

@Test
 public void testIncrementInstance() {
  final long expected = 13;
  Increment inc = new Increment(new byte [] {'r'});
  int total = 0;
  for (int i = 0; i < 2; i++) {
   byte [] bytes = Bytes.toBytes(i);
   inc.addColumn(bytes, bytes, expected);
   total++;
  }
  Map<byte[], NavigableMap<byte [], Long>> familyMapOfLongs = inc.getFamilyMapOfLongs();
  int found = 0;
  for (Map.Entry<byte [], NavigableMap<byte [], Long>> entry: familyMapOfLongs.entrySet()) {
   for (Map.Entry<byte [], Long> e: entry.getValue().entrySet()) {
    assertEquals(expected, e.getValue().longValue());
    found++;
   }
  }
  assertEquals(total, found);
 }
}

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

@Test
public void testIncrWithReadOnlyTable() throws Exception {
 final TableName tableName = TableName.valueOf(name.getMethodName());
 this.region = initHRegion(tableName, method, CONF, true, Bytes.toBytes("somefamily"));
 boolean exceptionCaught = false;
 Increment inc = new Increment(Bytes.toBytes("somerow"));
 inc.setDurability(Durability.SKIP_WAL);
 inc.addColumn(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"), 1L);
 try {
  region.increment(inc);
 } catch (IOException e) {
  exceptionCaught = true;
 }
 assertTrue(exceptionCaught == true);
}

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

@Override
 boolean testRow(final int i) throws IOException {
  Increment increment = new Increment(format(i));
  // unlike checkAndXXX tests, which make most sense to do on a single value,
  // if multiple families are specified for an increment 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);
   increment.addColumn(familyName, getQualifier(), 1l);
  }
  updateValueSize(this.table.increment(increment));
  return true;
 }
}

相关文章