use of org.apache.camel.component.hbase.model.HBaseCell 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;
}
use of org.apache.camel.component.hbase.model.HBaseCell in project camel by apache.
the class ModelAwareColumnMatchingFilter method apply.
/**
* Applies the message to {@link org.apache.hadoop.hbase.filter.Filter} to context.
*/
@Override
public void apply(CamelContext context, HBaseRow rowModel) {
fl.getFilters().clear();
if (rowModel != null) {
for (HBaseCell cell : rowModel.getCells()) {
if (cell.getValue() != null) {
byte[] family = HBaseHelper.getHBaseFieldAsBytes(cell.getFamily());
byte[] qualifier = HBaseHelper.getHBaseFieldAsBytes(cell.getQualifier());
byte[] value = context.getTypeConverter().convertTo(byte[].class, cell.getValue());
SingleColumnValueFilter columnValueFilter = new SingleColumnValueFilter(family, qualifier, CompareFilter.CompareOp.EQUAL, value);
fl.addFilter(columnValueFilter);
}
}
}
}
use of org.apache.camel.component.hbase.model.HBaseCell in project camel by apache.
the class HeaderMappingStrategy method applyScanResults.
/**
* Applies the cells to the {@link org.apache.camel.Exchange}.
*/
public void applyScanResults(Message message, HBaseData data) {
message.setHeaders(message.getExchange().getIn().getHeaders());
int index = 1;
if (data == null || data.getRows() == null) {
return;
}
for (HBaseRow hRow : data.getRows()) {
Set<HBaseCell> cells = hRow.getCells();
for (HBaseCell cell : cells) {
message.setHeader(HBaseAttribute.HBASE_ROW_ID.asHeader(index), hRow.getId());
message.setHeader(HBaseAttribute.HBASE_FAMILY.asHeader(index), cell.getFamily());
message.setHeader(HBaseAttribute.HBASE_QUALIFIER.asHeader(index), cell.getQualifier());
message.setHeader(HBaseAttribute.HBASE_VALUE.asHeader(index), cell.getValue());
}
index++;
}
}
use of org.apache.camel.component.hbase.model.HBaseCell in project camel by apache.
the class HeaderMappingStrategy method applyGetResults.
/**
* Applies the cells to the {@link org.apache.camel.Exchange}.
*/
public void applyGetResults(Message message, HBaseData data) {
message.setHeaders(message.getExchange().getIn().getHeaders());
int index = 1;
if (data == null || data.getRows() == null) {
return;
}
for (HBaseRow hRow : data.getRows()) {
if (hRow.getId() != null) {
Set<HBaseCell> cells = hRow.getCells();
for (HBaseCell cell : cells) {
message.setHeader(HBaseAttribute.HBASE_VALUE.asHeader(index++), getValueForColumn(cells, cell.getFamily(), cell.getQualifier()));
}
}
}
}
Aggregations