Search in sources :

Example 1 with BatchMutation

use of org.apache.hadoop.hbase.thrift.generated.BatchMutation in project hbase by apache.

the class TestThriftServer method getBatchMutations.

/**
   *
   * @return a List of BatchMutations with the following effects:
   * (rowA, columnA): delete
   * (rowA, columnB): place valueC
   * (rowB, columnA): place valueC
   * (rowB, columnB): place valueD
   */
private static List<BatchMutation> getBatchMutations() {
    List<BatchMutation> batchMutations = new ArrayList<>(3);
    // Mutations to rowA.  You can't mix delete and put anymore.
    List<Mutation> rowAmutations = new ArrayList<>(1);
    rowAmutations.add(new Mutation(true, columnAname, null, true));
    batchMutations.add(new BatchMutation(rowAname, rowAmutations));
    rowAmutations = new ArrayList<>(1);
    rowAmutations.add(new Mutation(false, columnBname, valueCname, true));
    batchMutations.add(new BatchMutation(rowAname, rowAmutations));
    // Mutations to rowB
    List<Mutation> rowBmutations = new ArrayList<>(2);
    rowBmutations.add(new Mutation(false, columnAname, valueCname, true));
    rowBmutations.add(new Mutation(false, columnBname, valueDname, true));
    batchMutations.add(new BatchMutation(rowBname, rowBmutations));
    return batchMutations;
}
Also used : ArrayList(java.util.ArrayList) BatchMutation(org.apache.hadoop.hbase.thrift.generated.BatchMutation) Mutation(org.apache.hadoop.hbase.thrift.generated.Mutation) BatchMutation(org.apache.hadoop.hbase.thrift.generated.BatchMutation)

Example 2 with BatchMutation

use of org.apache.hadoop.hbase.thrift.generated.BatchMutation in project hbase by apache.

the class TestThriftServer method doTestTableMutations.

public static void doTestTableMutations(Hbase.Iface handler) throws Exception {
    // Setup
    handler.createTable(tableAname, getColumnDescriptors());
    // Apply a few Mutations to rowA
    //     mutations.add(new Mutation(false, columnAname, valueAname));
    //     mutations.add(new Mutation(false, columnBname, valueBname));
    handler.mutateRow(tableAname, rowAname, getMutations(), null);
    // Assert that the changes were made
    assertEquals(valueAname, handler.get(tableAname, rowAname, columnAname, null).get(0).value);
    TRowResult rowResult1 = handler.getRow(tableAname, rowAname, null).get(0);
    assertEquals(rowAname, rowResult1.row);
    assertEquals(valueBname, rowResult1.columns.get(columnBname).value);
    // Apply a few BatchMutations for rowA and rowB
    // rowAmutations.add(new Mutation(true, columnAname, null));
    // rowAmutations.add(new Mutation(false, columnBname, valueCname));
    // batchMutations.add(new BatchMutation(rowAname, rowAmutations));
    // Mutations to rowB
    // rowBmutations.add(new Mutation(false, columnAname, valueCname));
    // rowBmutations.add(new Mutation(false, columnBname, valueDname));
    // batchMutations.add(new BatchMutation(rowBname, rowBmutations));
    handler.mutateRows(tableAname, getBatchMutations(), null);
    // Assert that changes were made to rowA
    List<TCell> cells = handler.get(tableAname, rowAname, columnAname, null);
    assertFalse(cells.size() > 0);
    assertEquals(valueCname, handler.get(tableAname, rowAname, columnBname, null).get(0).value);
    List<TCell> versions = handler.getVer(tableAname, rowAname, columnBname, MAXVERSIONS, null);
    assertEquals(valueCname, versions.get(0).value);
    assertEquals(valueBname, versions.get(1).value);
    // Assert that changes were made to rowB
    TRowResult rowResult2 = handler.getRow(tableAname, rowBname, null).get(0);
    assertEquals(rowBname, rowResult2.row);
    assertEquals(valueCname, rowResult2.columns.get(columnAname).value);
    assertEquals(valueDname, rowResult2.columns.get(columnBname).value);
    // Apply some deletes
    handler.deleteAll(tableAname, rowAname, columnBname, null);
    handler.deleteAllRow(tableAname, rowBname, null);
    // Assert that the deletes were applied
    int size = handler.get(tableAname, rowAname, columnBname, null).size();
    assertEquals(0, size);
    size = handler.getRow(tableAname, rowBname, null).size();
    assertEquals(0, size);
    // Try null mutation
    List<Mutation> mutations = new ArrayList<>(1);
    mutations.add(new Mutation(false, columnAname, null, true));
    handler.mutateRow(tableAname, rowAname, mutations, null);
    TRowResult rowResult3 = handler.getRow(tableAname, rowAname, null).get(0);
    assertEquals(rowAname, rowResult3.row);
    assertEquals(0, rowResult3.columns.get(columnAname).value.remaining());
    // Teardown
    handler.disableTable(tableAname);
    handler.deleteTable(tableAname);
}
Also used : ArrayList(java.util.ArrayList) TCell(org.apache.hadoop.hbase.thrift.generated.TCell) BatchMutation(org.apache.hadoop.hbase.thrift.generated.BatchMutation) Mutation(org.apache.hadoop.hbase.thrift.generated.Mutation) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult)

Aggregations

ArrayList (java.util.ArrayList)2 BatchMutation (org.apache.hadoop.hbase.thrift.generated.BatchMutation)2 Mutation (org.apache.hadoop.hbase.thrift.generated.Mutation)2 TCell (org.apache.hadoop.hbase.thrift.generated.TCell)1 TRowResult (org.apache.hadoop.hbase.thrift.generated.TRowResult)1