Search in sources :

Example 26 with TColumnValue

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

the class TestThriftHBaseServiceHandlerWithLabels method assertTColumnValuesEqual.

public void assertTColumnValuesEqual(List<TColumnValue> columnValuesA, List<TColumnValue> columnValuesB) {
    assertEquals(columnValuesA.size(), columnValuesB.size());
    Comparator<TColumnValue> comparator = new Comparator<TColumnValue>() {

        @Override
        public int compare(TColumnValue o1, TColumnValue o2) {
            return Bytes.compareTo(Bytes.add(o1.getFamily(), o1.getQualifier()), Bytes.add(o2.getFamily(), o2.getQualifier()));
        }
    };
    Collections.sort(columnValuesA, comparator);
    Collections.sort(columnValuesB, comparator);
    for (int i = 0; i < columnValuesA.size(); i++) {
        TColumnValue a = columnValuesA.get(i);
        TColumnValue b = columnValuesB.get(i);
        assertArrayEquals(a.getFamily(), b.getFamily());
        assertArrayEquals(a.getQualifier(), b.getQualifier());
        assertArrayEquals(a.getValue(), b.getValue());
    }
}
Also used : TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) Comparator(java.util.Comparator)

Example 27 with TColumnValue

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

the class TestThriftHBaseServiceHandlerWithLabels method testIncrementWithTags.

@Test
public void testIncrementWithTags() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = "testIncrementWithTags".getBytes();
    ByteBuffer table = wrap(tableAname);
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(Bytes.toBytes(1L))));
    TPut put = new TPut(wrap(rowName), columnValues);
    put.setColumnValues(columnValues);
    put.setCellVisibility(new TCellVisibility().setExpression(PRIVATE));
    handler.put(table, put);
    List<TColumnIncrement> incrementColumns = new ArrayList<>(1);
    incrementColumns.add(new TColumnIncrement(wrap(familyAname), wrap(qualifierAname)));
    TIncrement increment = new TIncrement(wrap(rowName), incrementColumns);
    increment.setCellVisibility(new TCellVisibility().setExpression(SECRET));
    handler.increment(table, increment);
    TGet get = new TGet(wrap(rowName));
    TAuthorization tauth = new TAuthorization();
    List<String> labels = new ArrayList<>(1);
    labels.add(SECRET);
    tauth.setLabels(labels);
    get.setAuthorizations(tauth);
    TResult result = handler.get(table, get);
    assertArrayEquals(rowName, result.getRow());
    assertEquals(1, result.getColumnValuesSize());
    TColumnValue columnValue = result.getColumnValues().get(0);
    assertArrayEquals(Bytes.toBytes(2L), columnValue.getValue());
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TIncrement(org.apache.hadoop.hbase.thrift2.generated.TIncrement) 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) TColumnIncrement(org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement) TCellVisibility(org.apache.hadoop.hbase.thrift2.generated.TCellVisibility) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 28 with TColumnValue

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

the class TestThriftHBaseServiceHandlerWithLabels method testAppend.

@Test
public void testAppend() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = "testAppend".getBytes();
    ByteBuffer table = wrap(tableAname);
    byte[] v1 = Bytes.toBytes(1L);
    byte[] v2 = Bytes.toBytes(5L);
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(Bytes.toBytes(1L))));
    TPut put = new TPut(wrap(rowName), columnValues);
    put.setColumnValues(columnValues);
    put.setCellVisibility(new TCellVisibility().setExpression(PRIVATE));
    handler.put(table, put);
    List<TColumnValue> appendColumns = new ArrayList<>(1);
    appendColumns.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(v2)));
    TAppend append = new TAppend(wrap(rowName), appendColumns);
    append.setCellVisibility(new TCellVisibility().setExpression(SECRET));
    handler.append(table, append);
    TGet get = new TGet(wrap(rowName));
    TAuthorization tauth = new TAuthorization();
    List<String> labels = new ArrayList<>(1);
    labels.add(SECRET);
    tauth.setLabels(labels);
    get.setAuthorizations(tauth);
    TResult result = handler.get(table, get);
    assertArrayEquals(rowName, result.getRow());
    assertEquals(1, result.getColumnValuesSize());
    TColumnValue columnValue = result.getColumnValues().get(0);
    assertArrayEquals(Bytes.add(v1, v2), columnValue.getValue());
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) 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) TCellVisibility(org.apache.hadoop.hbase.thrift2.generated.TCellVisibility) TAppend(org.apache.hadoop.hbase.thrift2.generated.TAppend) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 29 with TColumnValue

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

the class TestThriftHBaseServiceHandler method testScan.

@Test
public void testScan() 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);
        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());
    // get scanner and rows
    int scanId = handler.openScanner(table, scan);
    List<TResult> results = handler.getScannerRows(scanId, 10);
    assertEquals(10, results.size());
    for (int i = 0; i < 10; i++) {
        // check if the rows are returned and in order
        assertArrayEquals(("testScan" + i).getBytes(), results.get(i).getRow());
    }
    // check that we are at the end of the scan
    results = handler.getScannerRows(scanId, 10);
    assertEquals(0, results.size());
    // close scanner and check that it was indeed closed
    handler.closeScanner(scanId);
    try {
        handler.getScannerRows(scanId, 10);
        fail("Scanner id should be invalid");
    } catch (TIllegalArgument e) {
    }
}
Also used : TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) 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) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 30 with TColumnValue

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

the class TestThriftHBaseServiceHandler method testReverseScan.

@Test
public void testReverseScan() 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(("testReverseScan" + i).getBytes()), columnValues);
        handler.put(table, put);
    }
    // create reverse scan instance
    TScan scan = new TScan();
    scan.setReversed(true);
    List<TColumn> columns = new ArrayList<>(1);
    TColumn column = new TColumn();
    column.setFamily(familyAname);
    column.setQualifier(qualifierAname);
    columns.add(column);
    scan.setColumns(columns);
    scan.setStartRow("testReverseScan￿".getBytes());
    scan.setStopRow("testReverseScan".getBytes());
    // get scanner and rows
    int scanId = handler.openScanner(table, scan);
    List<TResult> results = handler.getScannerRows(scanId, 10);
    assertEquals(10, results.size());
    for (int i = 0; i < 10; i++) {
        // check if the rows are returned and in order
        assertArrayEquals(("testReverseScan" + (9 - i)).getBytes(), results.get(i).getRow());
    }
    // check that we are at the end of the scan
    results = handler.getScannerRows(scanId, 10);
    assertEquals(0, results.size());
    // close scanner and check that it was indeed closed
    handler.closeScanner(scanId);
    try {
        handler.getScannerRows(scanId, 10);
        fail("Scanner id should be invalid");
    } catch (TIllegalArgument e) {
    }
}
Also used : TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) 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) 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