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

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

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

Table.incrementColumnValue介绍

[英]See #incrementColumnValue(byte[],byte[],byte[],long,Durability)

The Durability is defaulted to Durability#SYNC_WAL.
[中]参见#incrementColumnValue(字节[],字节[],字节[],长,耐久性)
耐久性默认为耐久性#SYNC_WAL。

代码示例

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

  1. protected long atomicIncrement(ByteBuffer tableName, ByteBuffer row,
  2. byte [] family, byte [] qualifier, long amount)
  3. throws IOError, IllegalArgument, TException {
  4. Table table = null;
  5. try {
  6. table = getTable(tableName);
  7. return table.incrementColumnValue(
  8. getBytes(row), family, qualifier, amount);
  9. } catch (IOException e) {
  10. LOG.warn(e.getMessage(), e);
  11. throw getIOError(e);
  12. } finally {
  13. closeTable(table);
  14. }
  15. }

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

  1. throw new IOException("Auto-Fail rest of ICVs");
  2. table.incrementColumnValue(row.getRowKey(), row.getFamily(), row.getQualifier(),
  3. counter);
  4. } catch (IOException e) {

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

  1. @Test
  2. public void testIncrementWithDeletes() throws Exception {
  3. LOG.info("Starting " + this.name.getMethodName());
  4. final TableName TABLENAME =
  5. TableName.valueOf(filterStringSoTableNameSafe(this.name.getMethodName()));
  6. Table ht = TEST_UTIL.createTable(TABLENAME, FAMILY);
  7. final byte[] COLUMN = Bytes.toBytes("column");
  8. ht.incrementColumnValue(ROW, FAMILY, COLUMN, 5);
  9. TEST_UTIL.flush(TABLENAME);
  10. Delete del = new Delete(ROW);
  11. ht.delete(del);
  12. ht.incrementColumnValue(ROW, FAMILY, COLUMN, 5);
  13. Get get = new Get(ROW);
  14. Result r = ht.get(get);
  15. assertEquals(1, r.size());
  16. assertEquals(5, Bytes.toLong(r.getValue(FAMILY, COLUMN)));
  17. }

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

  1. @Override
  2. public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount,
  3. Durability durability) throws IOException {
  4. return delegate.incrementColumnValue(row, family, qualifier, amount, durability);
  5. }

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

  1. @Override
  2. public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount)
  3. throws IOException {
  4. return delegate.incrementColumnValue(row, family, qualifier, amount);
  5. }

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

  1. @Test
  2. public void testIncrementingInvalidValue() throws Exception {
  3. LOG.info("Starting " + this.name.getMethodName());
  4. final TableName TABLENAME =
  5. TableName.valueOf(filterStringSoTableNameSafe(this.name.getMethodName()));
  6. Table ht = TEST_UTIL.createTable(TABLENAME, FAMILY);
  7. final byte[] COLUMN = Bytes.toBytes("column");
  8. Put p = new Put(ROW);
  9. // write an integer here (not a Long)
  10. p.addColumn(FAMILY, COLUMN, Bytes.toBytes(5));
  11. ht.put(p);
  12. try {
  13. ht.incrementColumnValue(ROW, FAMILY, COLUMN, 5);
  14. fail("Should have thrown DoNotRetryIOException");
  15. } catch (DoNotRetryIOException iox) {
  16. // success
  17. }
  18. Increment inc = new Increment(ROW);
  19. inc.addColumn(FAMILY, COLUMN, 5);
  20. try {
  21. ht.increment(inc);
  22. fail("Should have thrown DoNotRetryIOException");
  23. } catch (DoNotRetryIOException iox) {
  24. // success
  25. }
  26. }

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

  1. try {
  2. try( Table table = TEST_UTIL.getConnection().getTable(tableName)) {
  3. table.incrementColumnValue(ROW1, FAM, FAM, 1);

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

  1. ht.incrementColumnValue(ROW, FAMILY, QUALIFIERS[0], 1);
  2. ht.incrementColumnValue(ROW, FAMILY, QUALIFIERS[1], 2);
  3. ht.incrementColumnValue(ROW, FAMILY, QUALIFIERS[2], 3);
  4. ht.incrementColumnValue(ROW, FAMILY, QUALIFIERS[3], 4);

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

  1. try {
  2. ht.incrementColumnValue(null, FAMILY, COLUMN, 5);
  3. fail("Should have thrown IOException");
  4. } catch (IOException iox) {
  5. ht.incrementColumnValue(ROW, null, COLUMN, 5);
  6. fail("Should have thrown IOException");
  7. } catch (IOException iox) {

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

  1. t -> t.put(new Put(Bytes.toBytes("row")).addColumn(CF, CQ, Bytes.toBytes("row"))));
  2. assertDisallow(table, t -> t.delete(new Delete(Bytes.toBytes("row"))));
  3. assertDisallow(table, t -> t.incrementColumnValue(Bytes.toBytes("row"), CF, CQ, 1));
  4. assertDisallow(table,
  5. t -> t.append(new Append(Bytes.toBytes("row")).addColumn(CF, CQ, Bytes.toBytes("row"))));

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

  1. @Override
  2. public Void run() throws Exception {
  3. try (Connection connection = ConnectionFactory.createConnection(conf)) {
  4. try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
  5. Increment inc = new Increment(TEST_ROW1);
  6. inc.setTimeRange(0, 123);
  7. inc.addColumn(TEST_FAMILY1, TEST_Q1, 2L);
  8. t.increment(inc);
  9. t.incrementColumnValue(TEST_ROW1, TEST_FAMILY1, TEST_Q2, 1L);
  10. }
  11. }
  12. return null;
  13. }
  14. });

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

  1. @Test
  2. public void testLabelsWithIncrement() 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(1L);
  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. table.incrementColumnValue(row1, fam, qual, 2L);
  16. result = table.get(get);
  17. assertTrue(result.isEmpty());
  18. Increment increment = new Increment(row1);
  19. increment.addColumn(fam, qual, 2L);
  20. increment.setCellVisibility(new CellVisibility(SECRET));
  21. table.increment(increment);
  22. result = table.get(get);
  23. assertTrue(!result.isEmpty());
  24. }
  25. }

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

  1. getTestNull(table, ROW, FAMILY, 1L);
  2. table.incrementColumnValue(ROW, FAMILY, null, 1L);
  3. getTestNull(table, ROW, FAMILY, 2L);

代码示例来源:origin: hugegraph/hugegraph

  1. /**
  2. * Increase a counter by rowkey and qualifier to a table
  3. */
  4. public long increase(String table, byte[] family, byte[] rowkey,
  5. byte[] qualifier, long value) {
  6. try (Table htable = table(table)) {
  7. return htable.incrementColumnValue(rowkey, family,
  8. qualifier, value);
  9. } catch (IOException e) {
  10. throw new BackendException(e);
  11. }
  12. }

代码示例来源:origin: larsgeorge/hbase-book

  1. public static void main(String[] args) throws IOException {
  2. Configuration conf = HBaseConfiguration.create();
  3. HBaseHelper helper = HBaseHelper.getHelper(conf);
  4. helper.dropTable("testtable");
  5. helper.createTable("testtable", "daily");
  6. Connection connection = ConnectionFactory.createConnection(conf);
  7. Table table = connection.getTable(TableName.valueOf("testtable"));
  8. // vv IncrementSingleExample
  9. long cnt1 = table.incrementColumnValue(Bytes.toBytes("20110101"), // co IncrementSingleExample-1-Incr1 Increase counter by one.
  10. Bytes.toBytes("daily"), Bytes.toBytes("hits"), 1);
  11. long cnt2 = table.incrementColumnValue(Bytes.toBytes("20110101"), // co IncrementSingleExample-2-Incr2 Increase counter by one a second time.
  12. Bytes.toBytes("daily"), Bytes.toBytes("hits"), 1);
  13. long current = table.incrementColumnValue(Bytes.toBytes("20110101"), // co IncrementSingleExample-3-GetCurrent Get current value of the counter without increasing it.
  14. Bytes.toBytes("daily"), Bytes.toBytes("hits"), 0);
  15. long cnt3 = table.incrementColumnValue(Bytes.toBytes("20110101"), // co IncrementSingleExample-4-Decr1 Decrease counter by one.
  16. Bytes.toBytes("daily"), Bytes.toBytes("hits"), -1);
  17. // ^^ IncrementSingleExample
  18. System.out.println("cnt1: " + cnt1 + ", cnt2: " + cnt2 +
  19. ", current: " + current + ", cnt3: " + cnt3);
  20. }
  21. }

代码示例来源:origin: larsgeorge/hbase-book

  1. table.incrementColumnValue(Bytes.toBytes("row10"),
  2. Bytes.toBytes("colfam1"), Bytes.toBytes("qual12"), 1);
  3. printStatistics(true, true);

代码示例来源:origin: Impetus/Kundera

  1. @Override
  2. public Object generate(TableGeneratorDiscriptor discriptor, ClientBase client, String dataType)
  3. {
  4. String tableName = HBaseUtils.getHTableName(discriptor.getSchema(), discriptor.getPkColumnValue());
  5. try
  6. {
  7. Table hTable = ((HBaseDataHandler) ((HBaseClient) client).handler).gethTable(tableName);
  8. Long latestCount = hTable.incrementColumnValue(HBaseUtils.AUTO_ID_ROW.getBytes(), discriptor
  9. .getPkColumnValue().getBytes(), discriptor.getValueColumnName().getBytes(), 1);
  10. if (latestCount == 1)
  11. {
  12. return (long) discriptor.getInitialValue();
  13. }
  14. else if (discriptor.getAllocationSize() == 1)
  15. {
  16. return latestCount + discriptor.getInitialValue();
  17. }
  18. else
  19. {
  20. return (latestCount - 1) * discriptor.getAllocationSize() + discriptor.getInitialValue();
  21. }
  22. }
  23. catch (IOException ioex)
  24. {
  25. log.error("Error while generating id for entity, Caused by: .", ioex);
  26. throw new KunderaException(ioex);
  27. }
  28. }
  29. }

代码示例来源:origin: org.apache.phoenix/phoenix-core

  1. @Override
  2. public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount)
  3. throws IOException {
  4. return delegate.incrementColumnValue(row, family, qualifier, amount);
  5. }

代码示例来源:origin: org.apache.phoenix/phoenix-core

  1. @Override
  2. public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount,
  3. Durability durability) throws IOException {
  4. return delegate.incrementColumnValue(row, family, qualifier, amount, durability);
  5. }

代码示例来源:origin: org.apache.tephra/tephra-hbase-compat-1.1

  1. @Override
  2. public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, long amount, Durability durability)
  3. throws IOException {
  4. if (allowNonTransactional) {
  5. return hTable.incrementColumnValue(row, family, qualifier, amount, durability);
  6. } else {
  7. throw new UnsupportedOperationException("Operation is not supported transactionally");
  8. }
  9. }

相关文章