Search in sources :

Example 11 with PrefixFilter

use of org.apache.hadoop.hbase.filter.PrefixFilter in project camel by apache.

the class ModelAwareRowPrefixMatchingFilter method apply.

/**
     * Applies the message to {@link org.apache.hadoop.hbase.filter.Filter} to
     * context.
     */
@Override
public void apply(CamelContext context, HBaseRow rowModel) {
    getFilters().clear();
    if (rowModel != null) {
        if (rowModel.getId() != null) {
            byte[] value = context.getTypeConverter().convertTo(byte[].class, rowModel.getId());
            PrefixFilter rowPrefixFilter = new PrefixFilter(value);
            addFilter(rowPrefixFilter);
        }
    }
}
Also used : PrefixFilter(org.apache.hadoop.hbase.filter.PrefixFilter)

Example 12 with PrefixFilter

use of org.apache.hadoop.hbase.filter.PrefixFilter in project drill by apache.

the class CompareFunctionsProcessor method visitRowKeyPrefixConvertExpression.

private Boolean visitRowKeyPrefixConvertExpression(ConvertExpression e, int prefixLength, LogicalExpression valueArg) {
    String encodingType = e.getEncodingType();
    rowKeyPrefixStartRow = HConstants.EMPTY_START_ROW;
    rowKeyPrefixStopRow = HConstants.EMPTY_START_ROW;
    rowKeyPrefixFilter = null;
    if ((encodingType.compareTo("UINT4_BE") == 0) || (encodingType.compareTo("UINT_BE") == 0)) {
        if (prefixLength != 4) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        int val;
        if ((valueArg instanceof IntExpression) == false) {
            return false;
        }
        val = ((IntExpression) valueArg).getInt();
        // For TIME_EPOCH_BE/BIGINT_BE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case "equal":
                rowKeyPrefixFilter = new PrefixFilter(ByteBuffer.allocate(4).putInt(val).array());
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val).array();
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "greater_than_or_equal_to":
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val).array();
                return true;
            case "greater_than":
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "less_than_or_equal_to":
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "less_than":
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val).array();
                return true;
        }
        return false;
    }
    if ((encodingType.compareTo("TIMESTAMP_EPOCH_BE") == 0) || (encodingType.compareTo("TIME_EPOCH_BE") == 0) || (encodingType.compareTo("UINT8_BE") == 0)) {
        if (prefixLength != 8) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        long val;
        if (encodingType.compareTo("TIME_EPOCH_BE") == 0) {
            if ((valueArg instanceof TimeExpression) == false) {
                return false;
            }
            val = ((TimeExpression) valueArg).getTime();
        } else if (encodingType.compareTo("UINT8_BE") == 0) {
            if ((valueArg instanceof LongExpression) == false) {
                return false;
            }
            val = ((LongExpression) valueArg).getLong();
        } else if (encodingType.compareTo("TIMESTAMP_EPOCH_BE") == 0) {
            if ((valueArg instanceof TimeStampExpression) == false) {
                return false;
            }
            val = ((TimeStampExpression) valueArg).getTimeStamp();
        } else {
            // Should not reach here.
            return false;
        }
        // For TIME_EPOCH_BE/BIGINT_BE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case "equal":
                rowKeyPrefixFilter = new PrefixFilter(ByteBuffer.allocate(8).putLong(val).array());
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val).array();
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "greater_than_or_equal_to":
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val).array();
                return true;
            case "greater_than":
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "less_than_or_equal_to":
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "less_than":
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val).array();
                return true;
        }
        return false;
    }
    if (encodingType.compareTo("DATE_EPOCH_BE") == 0) {
        if ((valueArg instanceof DateExpression) == false) {
            return false;
        }
        if (prefixLength != 8) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        final long MILLISECONDS_IN_A_DAY = (long) 1000 * 60 * 60 * 24;
        long dateToSet;
        // For DATE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case "equal":
                long startDate = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(startDate).array();
                long stopDate = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(stopDate).array();
                return true;
            case "greater_than_or_equal_to":
                dateToSet = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "greater_than":
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "less_than_or_equal_to":
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "less_than":
                dateToSet = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
        }
        return false;
    }
    return false;
}
Also used : DateExpression(org.apache.drill.common.expression.ValueExpressions.DateExpression) PrefixFilter(org.apache.hadoop.hbase.filter.PrefixFilter) IntExpression(org.apache.drill.common.expression.ValueExpressions.IntExpression) TimeExpression(org.apache.drill.common.expression.ValueExpressions.TimeExpression) LongExpression(org.apache.drill.common.expression.ValueExpressions.LongExpression) QuotedString(org.apache.drill.common.expression.ValueExpressions.QuotedString) TimeStampExpression(org.apache.drill.common.expression.ValueExpressions.TimeStampExpression)

Example 13 with PrefixFilter

use of org.apache.hadoop.hbase.filter.PrefixFilter in project drill by apache.

the class CompareFunctionsProcessor method visitRowKeyPrefixConvertExpression.

private Boolean visitRowKeyPrefixConvertExpression(ConvertExpression e, int prefixLength, LogicalExpression valueArg) {
    String encodingType = e.getEncodingType();
    rowKeyPrefixStartRow = HConstants.EMPTY_START_ROW;
    rowKeyPrefixStopRow = HConstants.EMPTY_START_ROW;
    rowKeyPrefixFilter = null;
    if ((encodingType.compareTo("UINT4_BE") == 0) || (encodingType.compareTo("UINT_BE") == 0)) {
        if (prefixLength != 4) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        int val;
        if ((valueArg instanceof IntExpression) == false) {
            return false;
        }
        val = ((IntExpression) valueArg).getInt();
        // For TIME_EPOCH_BE/BIGINT_BE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case "equal":
                rowKeyPrefixFilter = new PrefixFilter(ByteBuffer.allocate(4).putInt(val).array());
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val).array();
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "greater_than_or_equal_to":
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val).array();
                return true;
            case "greater_than":
                rowKeyPrefixStartRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "less_than_or_equal_to":
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val + 1).array();
                return true;
            case "less_than":
                rowKeyPrefixStopRow = ByteBuffer.allocate(4).putInt(val).array();
                return true;
        }
        return false;
    }
    if ((encodingType.compareTo("TIMESTAMP_EPOCH_BE") == 0) || (encodingType.compareTo("TIME_EPOCH_BE") == 0) || (encodingType.compareTo("UINT8_BE") == 0)) {
        if (prefixLength != 8) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        long val;
        if (encodingType.compareTo("TIME_EPOCH_BE") == 0) {
            if ((valueArg instanceof TimeExpression) == false) {
                return false;
            }
            val = ((TimeExpression) valueArg).getTime();
        } else if (encodingType.compareTo("UINT8_BE") == 0) {
            if ((valueArg instanceof LongExpression) == false) {
                return false;
            }
            val = ((LongExpression) valueArg).getLong();
        } else if (encodingType.compareTo("TIMESTAMP_EPOCH_BE") == 0) {
            if ((valueArg instanceof TimeStampExpression) == false) {
                return false;
            }
            val = ((TimeStampExpression) valueArg).getTimeStamp();
        } else {
            // Should not reach here.
            return false;
        }
        // For TIME_EPOCH_BE/BIGINT_BE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case "equal":
                rowKeyPrefixFilter = new PrefixFilter(ByteBuffer.allocate(8).putLong(val).array());
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val).array();
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "greater_than_or_equal_to":
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val).array();
                return true;
            case "greater_than":
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "less_than_or_equal_to":
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val + 1).array();
                return true;
            case "less_than":
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(val).array();
                return true;
        }
        return false;
    }
    if (encodingType.compareTo("DATE_EPOCH_BE") == 0) {
        if ((valueArg instanceof DateExpression) == false) {
            return false;
        }
        if (prefixLength != 8) {
            throw new RuntimeException("Invalid length(" + prefixLength + ") of row-key prefix");
        }
        final long MILLISECONDS_IN_A_DAY = (long) 1000 * 60 * 60 * 24;
        long dateToSet;
        // For DATE encoding, the operators that we push-down are =, <>, <, <=, >, >=
        switch(functionName) {
            case "equal":
                long startDate = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(startDate).array();
                long stopDate = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(stopDate).array();
                return true;
            case "greater_than_or_equal_to":
                dateToSet = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "greater_than":
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStartRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "less_than_or_equal_to":
                dateToSet = ((DateExpression) valueArg).getDate() + MILLISECONDS_IN_A_DAY;
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
            case "less_than":
                dateToSet = ((DateExpression) valueArg).getDate();
                rowKeyPrefixStopRow = ByteBuffer.allocate(8).putLong(dateToSet).array();
                return true;
        }
        return false;
    }
    return false;
}
Also used : DateExpression(org.apache.drill.common.expression.ValueExpressions.DateExpression) PrefixFilter(org.apache.hadoop.hbase.filter.PrefixFilter) IntExpression(org.apache.drill.common.expression.ValueExpressions.IntExpression) TimeExpression(org.apache.drill.common.expression.ValueExpressions.TimeExpression) LongExpression(org.apache.drill.common.expression.ValueExpressions.LongExpression) QuotedString(org.apache.drill.common.expression.ValueExpressions.QuotedString) TimeStampExpression(org.apache.drill.common.expression.ValueExpressions.TimeStampExpression)

Aggregations

PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)13 Filter (org.apache.hadoop.hbase.filter.Filter)6 Scan (org.apache.hadoop.hbase.client.Scan)5 FilterList (org.apache.hadoop.hbase.filter.FilterList)4 Test (org.junit.Test)4 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)3 DateExpression (org.apache.drill.common.expression.ValueExpressions.DateExpression)2 IntExpression (org.apache.drill.common.expression.ValueExpressions.IntExpression)2 LongExpression (org.apache.drill.common.expression.ValueExpressions.LongExpression)2 QuotedString (org.apache.drill.common.expression.ValueExpressions.QuotedString)2 TimeExpression (org.apache.drill.common.expression.ValueExpressions.TimeExpression)2 TimeStampExpression (org.apache.drill.common.expression.ValueExpressions.TimeStampExpression)2 Table (org.apache.hadoop.hbase.client.Table)2 RegexStringComparator (org.apache.hadoop.hbase.filter.RegexStringComparator)2 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)2 IOException (java.io.IOException)1 Map (java.util.Map)1 NavigableSet (java.util.NavigableSet)1 Path (javax.ws.rs.Path)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1