use of org.apache.camel.component.hbase.filters.ModelAwareFilter in project camel by apache.
the class HBaseProducer method scanCells.
/**
* Performs an HBase {@link Get} on a specific row, using a collection of values (family/column/value pairs).
* The result is <p>the most recent entry</p> for each column.
*/
private List<HBaseRow> scanCells(Table table, HBaseRow model, String start, String stop, Integer maxRowScan, List<Filter> filters) throws Exception {
List<HBaseRow> rowSet = new LinkedList<>();
HBaseRow startRow = new HBaseRow(model.getCells());
startRow.setId(start);
Scan scan;
if (start != null) {
scan = new Scan(Bytes.toBytes(start));
} else {
scan = new Scan();
}
if (ObjectHelper.isNotEmpty(stop)) {
scan.setStopRow(Bytes.toBytes(stop));
}
if (filters != null && !filters.isEmpty()) {
for (int i = 0; i < filters.size(); i++) {
((ModelAwareFilter<?>) filters.get(i)).apply(endpoint.getCamelContext(), model);
scan.setFilter(new FilterList(FilterList.Operator.MUST_PASS_ALL, ((ModelAwareFilter<?>) filters.get(i)).getFilteredList()));
}
}
Set<HBaseCell> cellModels = model.getCells();
for (HBaseCell cellModel : cellModels) {
String family = cellModel.getFamily();
String column = cellModel.getQualifier();
if (ObjectHelper.isNotEmpty(family) && ObjectHelper.isNotEmpty(column)) {
scan.addColumn(HBaseHelper.getHBaseFieldAsBytes(family), HBaseHelper.getHBaseFieldAsBytes(column));
}
}
ResultScanner resultScanner = table.getScanner(scan);
int count = 0;
Result result = resultScanner.next();
while (result != null && count < maxRowScan) {
HBaseRow resultRow = new HBaseRow();
resultRow.setId(endpoint.getCamelContext().getTypeConverter().convertTo(model.getRowType(), result.getRow()));
resultRow.setTimestamp(result.rawCells()[0].getTimestamp());
cellModels = model.getCells();
for (HBaseCell modelCell : cellModels) {
HBaseCell resultCell = new HBaseCell();
String family = modelCell.getFamily();
String column = modelCell.getQualifier();
resultRow.setId(endpoint.getCamelContext().getTypeConverter().convertTo(model.getRowType(), result.getRow()));
resultCell.setValue(endpoint.getCamelContext().getTypeConverter().convertTo(modelCell.getValueType(), result.getValue(HBaseHelper.getHBaseFieldAsBytes(family), HBaseHelper.getHBaseFieldAsBytes(column))));
resultCell.setFamily(modelCell.getFamily());
resultCell.setQualifier(modelCell.getQualifier());
Cell cell = result.getColumnLatestCell(HBaseHelper.getHBaseFieldAsBytes(family), HBaseHelper.getHBaseFieldAsBytes(column));
if (cell != null) {
resultCell.setTimestamp(cell.getTimestamp());
}
resultRow.getCells().add(resultCell);
}
rowSet.add(resultRow);
count++;
result = resultScanner.next();
}
return rowSet;
}
Aggregations