Search in sources :

Example 31 with TColumnValue

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

the class TestThriftHBaseServiceHandler method testPutGetMultiple.

@Test
public void testPutGetMultiple() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    byte[] rowName1 = "testPutGetMultiple1".getBytes();
    byte[] rowName2 = "testPutGetMultiple2".getBytes();
    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)));
    List<TPut> puts = new ArrayList<>(2);
    puts.add(new TPut(wrap(rowName1), columnValues));
    puts.add(new TPut(wrap(rowName2), columnValues));
    handler.putMultiple(table, puts);
    List<TGet> gets = new ArrayList<>(2);
    gets.add(new TGet(wrap(rowName1)));
    gets.add(new TGet(wrap(rowName2)));
    List<TResult> results = handler.getMultiple(table, gets);
    assertEquals(2, results.size());
    assertArrayEquals(rowName1, results.get(0).getRow());
    assertTColumnValuesEqual(columnValues, results.get(0).getColumnValues());
    assertArrayEquals(rowName2, results.get(1).getRow());
    assertTColumnValuesEqual(columnValues, results.get(1).getColumnValues());
}
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)

Example 32 with TColumnValue

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

the class TestThriftHBaseServiceHandler method testAttribute.

@Test
public void testAttribute() throws Exception {
    byte[] rowName = "testAttribute".getBytes();
    byte[] attributeKey = "attribute1".getBytes();
    byte[] attributeValue = "value1".getBytes();
    Map<ByteBuffer, ByteBuffer> attributes = new HashMap<>();
    attributes.put(wrap(attributeKey), wrap(attributeValue));
    TGet tGet = new TGet(wrap(rowName));
    tGet.setAttributes(attributes);
    Get get = getFromThrift(tGet);
    assertArrayEquals(get.getAttribute("attribute1"), attributeValue);
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
    TPut tPut = new TPut(wrap(rowName), columnValues);
    tPut.setAttributes(attributes);
    Put put = putFromThrift(tPut);
    assertArrayEquals(put.getAttribute("attribute1"), attributeValue);
    TScan tScan = new TScan();
    tScan.setAttributes(attributes);
    Scan scan = scanFromThrift(tScan);
    assertArrayEquals(scan.getAttribute("attribute1"), attributeValue);
    List<TColumnIncrement> incrementColumns = new ArrayList<>(1);
    incrementColumns.add(new TColumnIncrement(wrap(familyAname), wrap(qualifierAname)));
    TIncrement tIncrement = new TIncrement(wrap(rowName), incrementColumns);
    tIncrement.setAttributes(attributes);
    Increment increment = incrementFromThrift(tIncrement);
    assertArrayEquals(increment.getAttribute("attribute1"), attributeValue);
    TDelete tDelete = new TDelete(wrap(rowName));
    tDelete.setAttributes(attributes);
    Delete delete = deleteFromThrift(tDelete);
    assertArrayEquals(delete.getAttribute("attribute1"), attributeValue);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) HashMap(java.util.HashMap) TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) TIncrement(org.apache.hadoop.hbase.thrift2.generated.TIncrement) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Put(org.apache.hadoop.hbase.client.Put) Get(org.apache.hadoop.hbase.client.Get) TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) TColumnIncrement(org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement) TIncrement(org.apache.hadoop.hbase.thrift2.generated.TIncrement) Increment(org.apache.hadoop.hbase.client.Increment) TColumnIncrement(org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) Scan(org.apache.hadoop.hbase.client.Scan) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 33 with TColumnValue

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

the class TestThriftHBaseServiceHandler method testDeleteMultiple.

@Test
public void testDeleteMultiple() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    byte[] rowName1 = "testDeleteMultiple1".getBytes();
    byte[] rowName2 = "testDeleteMultiple2".getBytes();
    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)));
    List<TPut> puts = new ArrayList<>(2);
    puts.add(new TPut(wrap(rowName1), columnValues));
    puts.add(new TPut(wrap(rowName2), columnValues));
    handler.putMultiple(table, puts);
    List<TDelete> deletes = new ArrayList<>(2);
    deletes.add(new TDelete(wrap(rowName1)));
    deletes.add(new TDelete(wrap(rowName2)));
    List<TDelete> deleteResults = handler.deleteMultiple(table, deletes);
    // 0 means they were all successfully applies
    assertEquals(0, deleteResults.size());
    assertFalse(handler.exists(table, new TGet(wrap(rowName1))));
    assertFalse(handler.exists(table, new TGet(wrap(rowName2))));
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) 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) Test(org.junit.Test)

Example 34 with TColumnValue

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

the class ThriftUtilities method resultFromHBase.

/**
   * Creates a {@link TResult} (Thrift) from a {@link Result} (HBase).
   *
   * @param in the <code>Result</code> to convert
   *
   * @return converted result, returns an empty result if the input is <code>null</code>
   */
public static TResult resultFromHBase(Result in) {
    Cell[] raw = in.rawCells();
    TResult out = new TResult();
    byte[] row = in.getRow();
    if (row != null) {
        out.setRow(in.getRow());
    }
    List<TColumnValue> columnValues = new ArrayList<>(raw.length);
    for (Cell kv : raw) {
        TColumnValue col = new TColumnValue();
        col.setFamily(CellUtil.cloneFamily(kv));
        col.setQualifier(CellUtil.cloneQualifier(kv));
        col.setTimestamp(kv.getTimestamp());
        col.setValue(CellUtil.cloneValue(kv));
        if (kv.getTagsLength() > 0) {
            col.setTags(CellUtil.getTagArray(kv));
        }
        columnValues.add(col);
    }
    out.setColumnValues(columnValues);
    return out;
}
Also used : ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) Cell(org.apache.hadoop.hbase.Cell) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult)

Example 35 with TColumnValue

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

the class TestThriftHBaseServiceHandlerWithLabels method testScanWithVisibilityLabels.

@Test
public void testScanWithVisibilityLabels() 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 < 10; i++) {
        TPut put = new TPut(wrap(("testScan" + i).getBytes()), columnValues);
        if (i == 5) {
            put.setCellVisibility(new TCellVisibility().setExpression(PUBLIC));
        } else {
            put.setCellVisibility(new TCellVisibility().setExpression("(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET));
        }
        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("testScan".getBytes());
    scan.setStopRow("testScan￿".getBytes());
    TAuthorization tauth = new TAuthorization();
    List<String> labels = new ArrayList<>(2);
    labels.add(SECRET);
    labels.add(PRIVATE);
    tauth.setLabels(labels);
    scan.setAuthorizations(tauth);
    // get scanner and rows
    int scanId = handler.openScanner(table, scan);
    List<TResult> results = handler.getScannerRows(scanId, 10);
    assertEquals(9, results.size());
    Assert.assertFalse(Bytes.equals(results.get(5).getRow(), ("testScan" + 5).getBytes()));
    for (int i = 0; i < 9; i++) {
        if (i < 5) {
            assertArrayEquals(("testScan" + i).getBytes(), results.get(i).getRow());
        } else if (i == 5) {
            continue;
        } else {
            assertArrayEquals(("testScan" + (i + 1)).getBytes(), results.get(i).getRow());
        }
    }
    // check that we are at the end of the scan
    results = handler.getScannerRows(scanId, 9);
    assertEquals(0, results.size());
    // close scanner and check that it was indeed closed
    handler.closeScanner(scanId);
    try {
        handler.getScannerRows(scanId, 9);
        fail("Scanner id should be invalid");
    } catch (TIllegalArgument e) {
    }
}
Also used : TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TAuthorization(org.apache.hadoop.hbase.thrift2.generated.TAuthorization) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TIllegalArgument(org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) TCellVisibility(org.apache.hadoop.hbase.thrift2.generated.TCellVisibility) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) 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