Search in sources :

Example 6 with HBaseCell

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;
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) FilterList(org.apache.hadoop.hbase.filter.FilterList) LinkedList(java.util.LinkedList) HBaseCell(org.apache.camel.component.hbase.model.HBaseCell) Result(org.apache.hadoop.hbase.client.Result) HBaseRow(org.apache.camel.component.hbase.model.HBaseRow) ModelAwareFilter(org.apache.camel.component.hbase.filters.ModelAwareFilter) Scan(org.apache.hadoop.hbase.client.Scan) HBaseCell(org.apache.camel.component.hbase.model.HBaseCell) Cell(org.apache.hadoop.hbase.Cell)

Example 7 with HBaseCell

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);
            }
        }
    }
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) HBaseCell(org.apache.camel.component.hbase.model.HBaseCell)

Example 8 with HBaseCell

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++;
    }
}
Also used : HBaseRow(org.apache.camel.component.hbase.model.HBaseRow) HBaseCell(org.apache.camel.component.hbase.model.HBaseCell)

Example 9 with HBaseCell

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()));
            }
        }
    }
}
Also used : HBaseRow(org.apache.camel.component.hbase.model.HBaseRow) HBaseCell(org.apache.camel.component.hbase.model.HBaseCell)

Aggregations

HBaseCell (org.apache.camel.component.hbase.model.HBaseCell)9 HBaseRow (org.apache.camel.component.hbase.model.HBaseRow)7 LinkedList (java.util.LinkedList)3 Cell (org.apache.hadoop.hbase.Cell)3 Result (org.apache.hadoop.hbase.client.Result)3 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 Scan (org.apache.hadoop.hbase.client.Scan)2 FilterList (org.apache.hadoop.hbase.filter.FilterList)2 Exchange (org.apache.camel.Exchange)1 ModelAwareFilter (org.apache.camel.component.hbase.filters.ModelAwareFilter)1 CellMappingStrategy (org.apache.camel.component.hbase.mapping.CellMappingStrategy)1 HBaseData (org.apache.camel.component.hbase.model.HBaseData)1 DefaultEndpoint (org.apache.camel.impl.DefaultEndpoint)1 UriEndpoint (org.apache.camel.spi.UriEndpoint)1 Get (org.apache.hadoop.hbase.client.Get)1 Put (org.apache.hadoop.hbase.client.Put)1 Table (org.apache.hadoop.hbase.client.Table)1 Filter (org.apache.hadoop.hbase.filter.Filter)1 PageFilter (org.apache.hadoop.hbase.filter.PageFilter)1 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)1