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;
}
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);
}
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++;
}
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);
}
}
Aggregations