Search in sources :

Example 1 with TGet

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

the class ThriftUtilities method getFromThrift.

/**
   * Creates a {@link Get} (HBase) from a {@link TGet} (Thrift).
   *
   * This ignores any timestamps set on {@link TColumn} objects.
   *
   * @param in the <code>TGet</code> to convert
   *
   * @return <code>Get</code> object
   *
   * @throws IOException if an invalid time range or max version parameter is given
   */
public static Get getFromThrift(TGet in) throws IOException {
    Get out = new Get(in.getRow());
    // Timestamp overwrites time range if both are set
    if (in.isSetTimestamp()) {
        out.setTimeStamp(in.getTimestamp());
    } else if (in.isSetTimeRange()) {
        out.setTimeRange(in.getTimeRange().getMinStamp(), in.getTimeRange().getMaxStamp());
    }
    if (in.isSetMaxVersions()) {
        out.setMaxVersions(in.getMaxVersions());
    }
    if (in.isSetFilterString()) {
        ParseFilter parseFilter = new ParseFilter();
        out.setFilter(parseFilter.parseFilterString(in.getFilterString()));
    }
    if (in.isSetAttributes()) {
        addAttributes(out, in.getAttributes());
    }
    if (in.isSetAuthorizations()) {
        out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels()));
    }
    if (!in.isSetColumns()) {
        return out;
    }
    for (TColumn column : in.getColumns()) {
        if (column.isSetQualifier()) {
            out.addColumn(column.getFamily(), column.getQualifier());
        } else {
            out.addFamily(column.getFamily());
        }
    }
    return out;
}
Also used : Authorizations(org.apache.hadoop.hbase.security.visibility.Authorizations) ParseFilter(org.apache.hadoop.hbase.filter.ParseFilter) TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) Get(org.apache.hadoop.hbase.client.Get)

Example 2 with TGet

use of org.apache.hadoop.hbase.thrift2.generated.TGet 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 3 with TGet

use of org.apache.hadoop.hbase.thrift2.generated.TGet 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 4 with TGet

use of org.apache.hadoop.hbase.thrift2.generated.TGet 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 5 with TGet

use of org.apache.hadoop.hbase.thrift2.generated.TGet 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

TGet (org.apache.hadoop.hbase.thrift2.generated.TGet)26 ByteBuffer (java.nio.ByteBuffer)25 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)24 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)24 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)22 TResult (org.apache.hadoop.hbase.thrift2.generated.TResult)20 TDelete (org.apache.hadoop.hbase.thrift2.generated.TDelete)7 TColumn (org.apache.hadoop.hbase.thrift2.generated.TColumn)5 HashMap (java.util.HashMap)4 TAuthorization (org.apache.hadoop.hbase.thrift2.generated.TAuthorization)4 TCellVisibility (org.apache.hadoop.hbase.thrift2.generated.TCellVisibility)4 TColumnIncrement (org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement)4 THBaseService (org.apache.hadoop.hbase.thrift2.generated.THBaseService)4 TIncrement (org.apache.hadoop.hbase.thrift2.generated.TIncrement)4 Put (org.apache.hadoop.hbase.client.Put)3 ThriftMetrics (org.apache.hadoop.hbase.thrift.ThriftMetrics)3 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 TableName (org.apache.hadoop.hbase.TableName)2