Search in sources :

Example 11 with Column

use of org.apache.nifi.hbase.scan.Column in project nifi by apache.

the class HBase_1_1_2_RecordLookupService method getColumns.

private List<Column> getColumns(final String columnsValue) {
    final String[] columns = (columnsValue == null || columnsValue.isEmpty() ? new String[0] : columnsValue.split(","));
    final List<Column> columnsList = new ArrayList<>();
    for (final String column : columns) {
        if (column.contains(":")) {
            final String[] parts = column.trim().split(":");
            final byte[] cf = parts[0].getBytes(StandardCharsets.UTF_8);
            final byte[] cq = parts[1].getBytes(StandardCharsets.UTF_8);
            columnsList.add(new Column(cf, cq));
        } else {
            final byte[] cf = column.trim().getBytes(StandardCharsets.UTF_8);
            columnsList.add(new Column(cf, null));
        }
    }
    return columnsList;
}
Also used : Column(org.apache.nifi.hbase.scan.Column) ArrayList(java.util.ArrayList)

Example 12 with Column

use of org.apache.nifi.hbase.scan.Column in project nifi by apache.

the class TestHBase_1_1_2_ClientService method testScanWithInvalidFilter.

@Test(expected = IllegalArgumentException.class)
public void testScanWithInvalidFilter() throws InitializationException, IOException {
    final String tableName = "nifi";
    final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
    // Mock an HBase Table so we can verify the put operations later
    final Table table = Mockito.mock(Table.class);
    when(table.getName()).thenReturn(TableName.valueOf(tableName));
    // create the controller service and link it to the test processor
    final MockHBaseClientService service = configureHBaseClientService(runner, table);
    runner.assertValid(service);
    // perform a scan and verify the four rows were returned
    final CollectingResultHandler handler = new CollectingResultHandler();
    final HBaseClientService hBaseClientService = runner.getProcessContext().getProperty(TestProcessor.HBASE_CLIENT_SERVICE).asControllerService(HBaseClientService.class);
    // this should throw IllegalArgumentException
    final String filter = "this is not a filter";
    hBaseClientService.scan(tableName, new ArrayList<Column>(), filter, System.currentTimeMillis(), handler);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) PutColumn(org.apache.nifi.hbase.put.PutColumn) Column(org.apache.nifi.hbase.scan.Column) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 13 with Column

use of org.apache.nifi.hbase.scan.Column in project nifi by apache.

the class MockHBaseClientService method scan.

@Override
public void scan(String tableName, byte[] startRow, byte[] endRow, Collection<Column> columns, ResultHandler handler) throws IOException {
    if (throwException) {
        throw new IOException("exception");
    }
    for (final Map.Entry<String, ResultCell[]> entry : results.entrySet()) {
        List<ResultCell> matchedCells = new ArrayList<>();
        if (columns == null || columns.isEmpty()) {
            Arrays.stream(entry.getValue()).forEach(e -> matchedCells.add(e));
        } else {
            for (Column column : columns) {
                String colFam = new String(column.getFamily(), StandardCharsets.UTF_8);
                String colQual = new String(column.getQualifier(), StandardCharsets.UTF_8);
                for (ResultCell cell : entry.getValue()) {
                    String cellFam = new String(cell.getFamilyArray(), StandardCharsets.UTF_8);
                    String cellQual = new String(cell.getQualifierArray(), StandardCharsets.UTF_8);
                    if (colFam.equals(cellFam) && colQual.equals(cellQual)) {
                        matchedCells.add(cell);
                    }
                }
            }
        }
        handler.handle(entry.getKey().getBytes(StandardCharsets.UTF_8), matchedCells.toArray(new ResultCell[matchedCells.size()]));
    }
    numScans++;
}
Also used : PutColumn(org.apache.nifi.hbase.put.PutColumn) Column(org.apache.nifi.hbase.scan.Column) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ResultCell(org.apache.nifi.hbase.scan.ResultCell) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Column

use of org.apache.nifi.hbase.scan.Column in project nifi by apache.

the class TestGetHBase method testParseColumns.

@Test
public void testParseColumns() throws IOException {
    runner.setProperty(GetHBase.COLUMNS, "cf1,cf2:cq1,cf3");
    proc.parseColumns(runner.getProcessContext());
    final List<Column> expectedCols = new ArrayList<>();
    expectedCols.add(new Column("cf1".getBytes(Charset.forName("UTF-8")), null));
    expectedCols.add(new Column("cf2".getBytes(Charset.forName("UTF-8")), "cq1".getBytes(Charset.forName("UTF-8"))));
    expectedCols.add(new Column("cf3".getBytes(Charset.forName("UTF-8")), null));
    final List<Column> actualColumns = proc.getColumns();
    Assert.assertNotNull(actualColumns);
    Assert.assertEquals(expectedCols.size(), actualColumns.size());
    for (final Column expectedCol : expectedCols) {
        boolean found = false;
        for (final Column providedCol : actualColumns) {
            if (expectedCol.equals(providedCol)) {
                found = true;
                break;
            }
        }
        Assert.assertTrue("Didn't find expected column", found);
    }
}
Also used : Column(org.apache.nifi.hbase.scan.Column) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Column (org.apache.nifi.hbase.scan.Column)14 PutColumn (org.apache.nifi.hbase.put.PutColumn)7 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 Scan (org.apache.hadoop.hbase.client.Scan)3 Table (org.apache.hadoop.hbase.client.Table)3 TestRunner (org.apache.nifi.util.TestRunner)3 IOException (java.io.IOException)2 FlowFile (org.apache.nifi.flowfile.FlowFile)2 ResultCell (org.apache.nifi.hbase.scan.ResultCell)2 ProcessException (org.apache.nifi.processor.exception.ProcessException)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Filter (org.apache.hadoop.hbase.filter.Filter)1 ParseFilter (org.apache.hadoop.hbase.filter.ParseFilter)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 StateMap (org.apache.nifi.components.state.StateMap)1 DistributedMapCacheClient (org.apache.nifi.distributed.cache.client.DistributedMapCacheClient)1