Search in sources :

Example 1 with TColumnValue

use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.

the class TestThriftHBaseServiceHandler method testDeleteAllTimestamps.

@Test
public void testDeleteAllTimestamps() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = "testDeleteAllTimestamps".getBytes();
    ByteBuffer table = wrap(tableAname);
    List<TColumnValue> columnValues = new ArrayList<>(1);
    TColumnValue columnValueA = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    columnValueA.setTimestamp(System.currentTimeMillis() - 10);
    columnValues.add(columnValueA);
    TPut put = new TPut(wrap(rowName), columnValues);
    put.setColumnValues(columnValues);
    handler.put(table, put);
    columnValueA.setTimestamp(System.currentTimeMillis());
    handler.put(table, put);
    TGet get = new TGet(wrap(rowName));
    get.setMaxVersions(2);
    TResult result = handler.get(table, get);
    assertEquals(2, result.getColumnValuesSize());
    TDelete delete = new TDelete(wrap(rowName));
    List<TColumn> deleteColumns = new ArrayList<>(1);
    TColumn deleteColumn = new TColumn(wrap(familyAname));
    deleteColumn.setQualifier(qualifierAname);
    deleteColumns.add(deleteColumn);
    delete.setColumns(deleteColumns);
    // This is the default anyway.
    delete.setDeleteType(TDeleteType.DELETE_COLUMNS);
    handler.deleteSingle(table, delete);
    get = new TGet(wrap(rowName));
    result = handler.get(table, get);
    assertNull(result.getRow());
    assertEquals(0, result.getColumnValuesSize());
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) Test(org.junit.Test)

Example 2 with TColumnValue

use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.

the class TestThriftHBaseServiceHandler method testMutateRow.

/**
   * Put valueA to a row, make sure put has happened, then create a mutation object to put valueB
   * and delete ValueA, then check that the row value is only valueB.
   *
   * @throws Exception
   */
@Test
public void testMutateRow() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = "testMutateRow".getBytes();
    ByteBuffer table = wrap(tableAname);
    List<TColumnValue> columnValuesA = new ArrayList<>(1);
    TColumnValue columnValueA = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    columnValuesA.add(columnValueA);
    TPut putA = new TPut(wrap(rowName), columnValuesA);
    putA.setColumnValues(columnValuesA);
    handler.put(table, putA);
    TGet get = new TGet(wrap(rowName));
    TResult result = handler.get(table, get);
    assertArrayEquals(rowName, result.getRow());
    List<TColumnValue> returnedColumnValues = result.getColumnValues();
    List<TColumnValue> expectedColumnValues = new ArrayList<>(1);
    expectedColumnValues.add(columnValueA);
    assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues);
    List<TColumnValue> columnValuesB = new ArrayList<>(1);
    TColumnValue columnValueB = new TColumnValue(wrap(familyAname), wrap(qualifierBname), wrap(valueBname));
    columnValuesB.add(columnValueB);
    TPut putB = new TPut(wrap(rowName), columnValuesB);
    putB.setColumnValues(columnValuesB);
    TDelete delete = new TDelete(wrap(rowName));
    List<TColumn> deleteColumns = new ArrayList<>(1);
    TColumn deleteColumn = new TColumn(wrap(familyAname));
    deleteColumn.setQualifier(qualifierAname);
    deleteColumns.add(deleteColumn);
    delete.setColumns(deleteColumns);
    List<TMutation> mutations = new ArrayList<>(2);
    TMutation mutationA = TMutation.put(putB);
    mutations.add(mutationA);
    TMutation mutationB = TMutation.deleteSingle(delete);
    mutations.add(mutationB);
    TRowMutations tRowMutations = new TRowMutations(wrap(rowName), mutations);
    handler.mutateRow(table, tRowMutations);
    result = handler.get(table, get);
    assertArrayEquals(rowName, result.getRow());
    returnedColumnValues = result.getColumnValues();
    expectedColumnValues = new ArrayList<>(1);
    expectedColumnValues.add(columnValueB);
    assertTColumnValuesEqual(expectedColumnValues, returnedColumnValues);
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TMutation(org.apache.hadoop.hbase.thrift2.generated.TMutation) TRowMutations(org.apache.hadoop.hbase.thrift2.generated.TRowMutations) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 3 with TColumnValue

use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.

the class TestThriftHBaseServiceHandler method testExistsAll.

@Test
public void testExistsAll() throws TIOError, TException {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName1 = "testExistsAll1".getBytes();
    byte[] rowName2 = "testExistsAll2".getBytes();
    ByteBuffer table = wrap(tableAname);
    List<TGet> gets = new ArrayList<>();
    gets.add(new TGet(wrap(rowName2)));
    gets.add(new TGet(wrap(rowName2)));
    List<Boolean> existsResult1 = handler.existsAll(table, gets);
    assertFalse(existsResult1.get(0));
    assertFalse(existsResult1.get(1));
    List<TColumnValue> columnValues = new ArrayList<TColumnValue>();
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
    columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
    List<TPut> puts = new ArrayList<TPut>();
    puts.add(new TPut(wrap(rowName1), columnValues));
    puts.add(new TPut(wrap(rowName2), columnValues));
    handler.putMultiple(table, puts);
    List<Boolean> existsResult2 = handler.existsAll(table, gets);
    assertTrue(existsResult2.get(0));
    assertTrue(existsResult2.get(1));
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with TColumnValue

use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.

the class TestThriftHBaseServiceHandler method testGetScannerResults.

@Test
public void testGetScannerResults() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    // insert data
    TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(columnValue);
    for (int i = 0; i < 20; i++) {
        TPut put = new TPut(wrap(("testGetScannerResults" + pad(i, (byte) 2)).getBytes()), columnValues);
        handler.put(table, put);
    }
    // create scan instance
    TScan scan = new TScan();
    List<TColumn> columns = new ArrayList<>(1);
    TColumn column = new TColumn();
    column.setFamily(familyAname);
    column.setQualifier(qualifierAname);
    columns.add(column);
    scan.setColumns(columns);
    scan.setStartRow("testGetScannerResults".getBytes());
    // get 5 rows and check the returned results
    scan.setStopRow("testGetScannerResults05".getBytes());
    List<TResult> results = handler.getScannerResults(table, scan, 5);
    assertEquals(5, results.size());
    for (int i = 0; i < 5; i++) {
        // check if the rows are returned and in order
        assertArrayEquals(("testGetScannerResults" + pad(i, (byte) 2)).getBytes(), results.get(i).getRow());
    }
    // get 10 rows and check the returned results
    scan.setStopRow("testGetScannerResults10".getBytes());
    results = handler.getScannerResults(table, scan, 10);
    assertEquals(10, results.size());
    for (int i = 0; i < 10; i++) {
        // check if the rows are returned and in order
        assertArrayEquals(("testGetScannerResults" + pad(i, (byte) 2)).getBytes(), results.get(i).getRow());
    }
    // get 20 rows and check the returned results
    scan.setStopRow("testGetScannerResults20".getBytes());
    results = handler.getScannerResults(table, scan, 20);
    assertEquals(20, results.size());
    for (int i = 0; i < 20; i++) {
        // check if the rows are returned and in order
        assertArrayEquals(("testGetScannerResults" + pad(i, (byte) 2)).getBytes(), results.get(i).getRow());
    }
    // reverse scan
    scan = new TScan();
    scan.setColumns(columns);
    scan.setReversed(true);
    scan.setStartRow("testGetScannerResults20".getBytes());
    scan.setStopRow("testGetScannerResults".getBytes());
    results = handler.getScannerResults(table, scan, 20);
    assertEquals(20, results.size());
    for (int i = 0; i < 20; i++) {
        // check if the rows are returned and in order
        assertArrayEquals(("testGetScannerResults" + pad(19 - i, (byte) 2)).getBytes(), results.get(i).getRow());
    }
}
Also used : TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) Test(org.junit.Test)

Example 5 with TColumnValue

use of org.apache.hadoop.hbase.thrift2.generated.TColumnValue in project hbase by apache.

the class TestThriftHBaseServiceHandler method testPutGet.

@Test
public void testPutGet() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = "testPutGet".getBytes();
    ByteBuffer table = wrap(tableAname);
    List<TColumnValue> columnValues = new ArrayList<>(2);
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
    columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
    TPut put = new TPut(wrap(rowName), columnValues);
    put.setColumnValues(columnValues);
    handler.put(table, put);
    TGet get = new TGet(wrap(rowName));
    TResult result = handler.get(table, get);
    assertArrayEquals(rowName, result.getRow());
    List<TColumnValue> returnedColumnValues = result.getColumnValues();
    assertTColumnValuesEqual(columnValues, returnedColumnValues);
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) Test(org.junit.Test)

Aggregations

TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)37 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)34 ByteBuffer (java.nio.ByteBuffer)33 ArrayList (java.util.ArrayList)33 Test (org.junit.Test)33 TResult (org.apache.hadoop.hbase.thrift2.generated.TResult)29 TGet (org.apache.hadoop.hbase.thrift2.generated.TGet)24 TColumn (org.apache.hadoop.hbase.thrift2.generated.TColumn)12 TScan (org.apache.hadoop.hbase.thrift2.generated.TScan)10 TDelete (org.apache.hadoop.hbase.thrift2.generated.TDelete)8 TAuthorization (org.apache.hadoop.hbase.thrift2.generated.TAuthorization)6 TCellVisibility (org.apache.hadoop.hbase.thrift2.generated.TCellVisibility)6 TIllegalArgument (org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument)6 TColumnIncrement (org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement)5 TIncrement (org.apache.hadoop.hbase.thrift2.generated.TIncrement)5 HashMap (java.util.HashMap)4 Put (org.apache.hadoop.hbase.client.Put)4 THBaseService (org.apache.hadoop.hbase.thrift2.generated.THBaseService)4 ThriftMetrics (org.apache.hadoop.hbase.thrift.ThriftMetrics)3 Comparator (java.util.Comparator)2