Search in sources :

Example 36 with Increment

use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.

the class TestAccessController method testWrite.

@Test
public // test put, delete, increment
void testWrite() throws Exception {
    // put action
    AccessTestAction putAction = new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            Put p = new Put(TEST_ROW);
            p.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(1));
            try (Connection conn = ConnectionFactory.createConnection(conf);
                Table t = conn.getTable(TEST_TABLE)) {
                t.put(p);
            }
            return null;
        }
    };
    verifyWrite(putAction);
    // delete action
    AccessTestAction deleteAction = new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            Delete d = new Delete(TEST_ROW);
            d.addFamily(TEST_FAMILY);
            try (Connection conn = ConnectionFactory.createConnection(conf);
                Table t = conn.getTable(TEST_TABLE)) {
                t.delete(d);
            }
            return null;
        }
    };
    verifyWrite(deleteAction);
    // increment action
    AccessTestAction incrementAction = new AccessTestAction() {

        @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;
        }
    };
    verifyWrite(incrementAction);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) Increment(org.apache.hadoop.hbase.client.Increment) Connection(org.apache.hadoop.hbase.client.Connection) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 37 with Increment

use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.

the class TestSpaceQuotaBasicFunctioning method testNoInsertsWithIncrement.

@Test
public void testNoInsertsWithIncrement() throws Exception {
    Increment i = new Increment(Bytes.toBytes("to_reject"));
    i.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("count"), 0);
    helper.writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_INSERTS, i);
}
Also used : Increment(org.apache.hadoop.hbase.client.Increment) Test(org.junit.Test)

Example 38 with Increment

use of org.apache.hadoop.hbase.client.Increment in project hbase by apache.

the class TestSpaceQuotaBasicFunctioning method testNoWritesWithIncrement.

@Test
public void testNoWritesWithIncrement() throws Exception {
    Increment i = new Increment(Bytes.toBytes("to_reject"));
    i.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("count"), 0);
    helper.writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_WRITES, i);
}
Also used : Increment(org.apache.hadoop.hbase.client.Increment) Test(org.junit.Test)

Example 39 with Increment

use of org.apache.hadoop.hbase.client.Increment in project metron by apache.

the class HBaseClient method addMutation.

/**
 * Adds a Mutation such as a Put or Increment with a time to live.  The Mutation is only queued
 * for later execution.
 *
 * @param rowKey           The row key of the Mutation.
 * @param cols             The columns affected by the Mutation.
 * @param durability       The durability of the mutation.
 * @param timeToLiveMillis The time to live in milliseconds.
 */
public void addMutation(byte[] rowKey, ColumnList cols, Durability durability, Long timeToLiveMillis) {
    if (cols.hasColumns()) {
        Put put = createPut(rowKey, cols, durability, timeToLiveMillis);
        mutations.add(put);
    }
    if (cols.hasCounters()) {
        Increment inc = createIncrement(rowKey, cols, durability, timeToLiveMillis);
        mutations.add(inc);
    }
    if (mutations.isEmpty()) {
        Put put = new Put(rowKey);
        put.setTTL(timeToLiveMillis);
        mutations.add(put);
    }
}
Also used : Increment(org.apache.hadoop.hbase.client.Increment) Put(org.apache.hadoop.hbase.client.Put)

Example 40 with Increment

use of org.apache.hadoop.hbase.client.Increment in project metron by apache.

the class HBaseClient method createIncrement.

/**
 * Creates an HBase Increment for a counter.
 *
 * @param rowKey     The row key.
 * @param cols       The columns to include.
 * @param durability The durability of the increment.
 */
private Increment createIncrement(byte[] rowKey, ColumnList cols, Durability durability, long timeToLiveMillis) {
    Increment inc = new Increment(rowKey);
    inc.setDurability(durability);
    inc.setTTL(timeToLiveMillis);
    cols.getCounters().forEach(cnt -> inc.addColumn(cnt.getFamily(), cnt.getQualifier(), cnt.getIncrement()));
    return inc;
}
Also used : Increment(org.apache.hadoop.hbase.client.Increment)

Aggregations

Increment (org.apache.hadoop.hbase.client.Increment)81 Test (org.junit.Test)42 Put (org.apache.hadoop.hbase.client.Put)31 Append (org.apache.hadoop.hbase.client.Append)25 Result (org.apache.hadoop.hbase.client.Result)25 Delete (org.apache.hadoop.hbase.client.Delete)21 Get (org.apache.hadoop.hbase.client.Get)19 IOException (java.io.IOException)16 TableName (org.apache.hadoop.hbase.TableName)15 Table (org.apache.hadoop.hbase.client.Table)15 ArrayList (java.util.ArrayList)14 Cell (org.apache.hadoop.hbase.Cell)11 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)11 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)9 Mutation (org.apache.hadoop.hbase.client.Mutation)9 RowMutations (org.apache.hadoop.hbase.client.RowMutations)9 List (java.util.List)8 Map (java.util.Map)8 Scan (org.apache.hadoop.hbase.client.Scan)7 KeyValue (org.apache.hadoop.hbase.KeyValue)5