Search in sources :

Example 1 with TIllegalArgument

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

the class TestThriftHBaseServiceHandler method testScanWithBatchSize.

@Test
public void testScanWithBatchSize() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    // insert data
    List<TColumnValue> columnValues = new ArrayList<>(100);
    for (int i = 0; i < 100; i++) {
        String colNum = pad(i, (byte) 3);
        TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(("col" + colNum).getBytes()), wrap(("val" + colNum).getBytes()));
        columnValues.add(columnValue);
    }
    TPut put = new TPut(wrap(("testScanWithBatchSize").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);
    columns.add(column);
    scan.setColumns(columns);
    scan.setStartRow("testScanWithBatchSize".getBytes());
    scan.setStopRow("testScanWithBatchSize￿".getBytes());
    // set batch size to 10 columns per call
    scan.setBatchSize(10);
    // get scanner
    int scanId = handler.openScanner(table, scan);
    List<TResult> results = null;
    for (int i = 0; i < 10; i++) {
        // get batch for single row (10x10 is what we expect)
        results = handler.getScannerRows(scanId, 1);
        assertEquals(1, results.size());
        // check length of batch
        List<TColumnValue> cols = results.get(0).getColumnValues();
        assertEquals(10, cols.size());
        // check if the columns are returned and in order
        for (int y = 0; y < 10; y++) {
            int colNum = y + (10 * i);
            String colNumPad = pad(colNum, (byte) 3);
            assertArrayEquals(("col" + colNumPad).getBytes(), cols.get(y).getQualifier());
        }
    }
    // check that we are at the end of the scan
    results = handler.getScannerRows(scanId, 1);
    assertEquals(0, results.size());
    // close scanner and check that it was indeed closed
    handler.closeScanner(scanId);
    try {
        handler.getScannerRows(scanId, 1);
        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 2 with TIllegalArgument

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

the class TestThriftHBaseServiceHandler method testScanWithFilter.

@Test
public void testScanWithFilter() 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(("testScanWithFilter" + i).getBytes()), columnValues);
        handler.put(table, put);
    }
    // create scan instance with filter
    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("testScanWithFilter".getBytes());
    scan.setStopRow("testScanWithFilter￿".getBytes());
    // only get the key part
    scan.setFilterString(wrap(("KeyOnlyFilter()").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(("testScanWithFilter" + i).getBytes(), results.get(i).getRow());
        // check that the value is indeed stripped by the filter
        assertEquals(0, results.get(i).getColumnValues().get(0).getValue().length);
    }
    // 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 3 with TIllegalArgument

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

the class ThriftHBaseServiceHandler method getScannerRows.

@Override
public List<TResult> getScannerRows(int scannerId, int numRows) throws TIOError, TIllegalArgument, TException {
    ResultScanner scanner = getScanner(scannerId);
    if (scanner == null) {
        TIllegalArgument ex = new TIllegalArgument();
        ex.setMessage("Invalid scanner Id");
        throw ex;
    }
    try {
        connectionCache.updateConnectionAccessTime();
        return resultsFromHBase(scanner.next(numRows));
    } catch (IOException e) {
        throw getTIOError(e);
    }
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) TIllegalArgument(org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument) IOException(java.io.IOException)

Example 4 with TIllegalArgument

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

the class ThriftHBaseServiceHandler method closeScanner.

@Override
public void closeScanner(int scannerId) throws TIOError, TIllegalArgument, TException {
    LOG.debug("scannerClose: id=" + scannerId);
    ResultScanner scanner = getScanner(scannerId);
    if (scanner == null) {
        String message = "scanner ID is invalid";
        LOG.warn(message);
        TIllegalArgument ex = new TIllegalArgument();
        ex.setMessage("Invalid scanner Id");
        throw ex;
    }
    scanner.close();
    removeScanner(scannerId);
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) TIllegalArgument(org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument)

Example 5 with TIllegalArgument

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

the class TestThriftHBaseServiceHandler method testScanWithColumnFamilyTimeRange.

@Test
public void testScanWithColumnFamilyTimeRange() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    // insert data
    TColumnValue familyAColumnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    TColumnValue familyBColumnValue = new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname));
    long minTimestamp = System.currentTimeMillis();
    for (int i = 0; i < 10; i++) {
        familyAColumnValue.setTimestamp(minTimestamp + i);
        familyBColumnValue.setTimestamp(minTimestamp + i);
        List<TColumnValue> columnValues = new ArrayList<>(2);
        columnValues.add(familyAColumnValue);
        columnValues.add(familyBColumnValue);
        TPut put = new TPut(wrap(("testScanWithColumnFamilyTimeRange" + i).getBytes()), columnValues);
        handler.put(table, put);
    }
    // create scan instance with column family time range
    TScan scan = new TScan();
    Map<ByteBuffer, TTimeRange> colFamTimeRangeMap = new HashMap<>(2);
    colFamTimeRangeMap.put(wrap(familyAname), new TTimeRange(minTimestamp + 3, minTimestamp + 5));
    colFamTimeRangeMap.put(wrap(familyBname), new TTimeRange(minTimestamp + 6, minTimestamp + 9));
    scan.setColFamTimeRangeMap(colFamTimeRangeMap);
    // get scanner and rows
    int scanId = handler.openScanner(table, scan);
    List<TResult> results = handler.getScannerRows(scanId, 5);
    assertEquals(5, results.size());
    int familyACount = 0;
    int familyBCount = 0;
    for (TResult result : results) {
        List<TColumnValue> columnValues = result.getColumnValues();
        if (CollectionUtils.isNotEmpty(columnValues)) {
            if (Bytes.equals(familyAname, columnValues.get(0).getFamily())) {
                familyACount++;
            } else if (Bytes.equals(familyBname, columnValues.get(0).getFamily())) {
                familyBCount++;
            }
        }
    }
    assertEquals(2, familyACount);
    assertEquals(3, familyBCount);
    // check that we are at the end of the scan
    results = handler.getScannerRows(scanId, 1);
    assertEquals(0, results.size());
    // close scanner and check that it was indeed closed
    handler.closeScanner(scanId);
    try {
        handler.getScannerRows(scanId, 1);
        fail("Scanner id should be invalid");
    } catch (TIllegalArgument e) {
    }
}
Also used : HashMap(java.util.HashMap) TTimeRange(org.apache.hadoop.hbase.thrift2.generated.TTimeRange) 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

TIllegalArgument (org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument)8 ByteBuffer (java.nio.ByteBuffer)6 ArrayList (java.util.ArrayList)6 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)6 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)6 TResult (org.apache.hadoop.hbase.thrift2.generated.TResult)6 TScan (org.apache.hadoop.hbase.thrift2.generated.TScan)6 Test (org.junit.Test)6 TColumn (org.apache.hadoop.hbase.thrift2.generated.TColumn)5 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 TAuthorization (org.apache.hadoop.hbase.thrift2.generated.TAuthorization)1 TCellVisibility (org.apache.hadoop.hbase.thrift2.generated.TCellVisibility)1 TTimeRange (org.apache.hadoop.hbase.thrift2.generated.TTimeRange)1