Search in sources :

Example 1 with SingleCFCQKeyValueComparisonFilter

use of org.apache.phoenix.filter.SingleCFCQKeyValueComparisonFilter in project phoenix by apache.

the class WhereCompiler method setScanFilter.

/**
 * Sets the start/stop key range based on the whereClause expression.
 * @param context the shared context during query compilation
 * @param whereClause the final where clause expression.
 */
private static void setScanFilter(StatementContext context, FilterableStatement statement, Expression whereClause, boolean disambiguateWithFamily, boolean hashJoinOptimization) {
    Scan scan = context.getScan();
    if (LiteralExpression.isBooleanFalseOrNull(whereClause)) {
        context.setScanRanges(ScanRanges.NOTHING);
    } else if (whereClause != null && !ExpressionUtil.evaluatesToTrue(whereClause) && !hashJoinOptimization) {
        Filter filter = null;
        final Counter counter = new Counter();
        whereClause.accept(new KeyValueExpressionVisitor() {

            @Override
            public Iterator<Expression> defaultIterator(Expression node) {
                // Stop traversal once we've found multiple KeyValue columns
                if (counter.getCount() == Counter.Count.MULTIPLE) {
                    return Collections.emptyIterator();
                }
                return super.defaultIterator(node);
            }

            @Override
            public Void visit(KeyValueColumnExpression expression) {
                counter.increment(expression);
                return null;
            }
        });
        PTable table = context.getCurrentTable().getTable();
        QualifierEncodingScheme encodingScheme = table.getEncodingScheme();
        ImmutableStorageScheme storageScheme = table.getImmutableStorageScheme();
        Counter.Count count = counter.getCount();
        boolean allCFs = false;
        byte[] essentialCF = null;
        if (counter.getCount() == Counter.Count.SINGLE && whereClause.requiresFinalEvaluation()) {
            if (table.getViewType() == ViewType.MAPPED) {
                allCFs = true;
            } else {
                byte[] emptyCF = SchemaUtil.getEmptyColumnFamily(table);
                if (Bytes.compareTo(emptyCF, counter.getColumn().getColumnFamily()) != 0) {
                    essentialCF = emptyCF;
                    count = Counter.Count.MULTIPLE;
                }
            }
        }
        switch(count) {
            case NONE:
                essentialCF = table.getType() == PTableType.VIEW ? ByteUtil.EMPTY_BYTE_ARRAY : SchemaUtil.getEmptyColumnFamily(table);
                filter = new RowKeyComparisonFilter(whereClause, essentialCF);
                break;
            case SINGLE:
                filter = disambiguateWithFamily ? new SingleCFCQKeyValueComparisonFilter(whereClause) : new SingleCQKeyValueComparisonFilter(whereClause);
                break;
            case MULTIPLE:
                filter = isPossibleToUseEncodedCQFilter(encodingScheme, storageScheme) ? new MultiEncodedCQKeyValueComparisonFilter(whereClause, encodingScheme, allCFs, essentialCF) : (disambiguateWithFamily ? new MultiCFCQKeyValueComparisonFilter(whereClause, allCFs, essentialCF) : new MultiCQKeyValueComparisonFilter(whereClause, allCFs, essentialCF));
                break;
        }
        scan.setFilter(filter);
    }
    ScanRanges scanRanges = context.getScanRanges();
    if (scanRanges.useSkipScanFilter()) {
        ScanUtil.andFilterAtBeginning(scan, scanRanges.getSkipScanFilter());
    }
}
Also used : MultiCQKeyValueComparisonFilter(org.apache.phoenix.filter.MultiCQKeyValueComparisonFilter) SingleCFCQKeyValueComparisonFilter(org.apache.phoenix.filter.SingleCFCQKeyValueComparisonFilter) MultiEncodedCQKeyValueComparisonFilter(org.apache.phoenix.filter.MultiEncodedCQKeyValueComparisonFilter) KeyValueExpressionVisitor(org.apache.phoenix.expression.visitor.KeyValueExpressionVisitor) PTable(org.apache.phoenix.schema.PTable) QualifierEncodingScheme(org.apache.phoenix.schema.PTable.QualifierEncodingScheme) MultiCFCQKeyValueComparisonFilter(org.apache.phoenix.filter.MultiCFCQKeyValueComparisonFilter) RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) SingleCFCQKeyValueComparisonFilter(org.apache.phoenix.filter.SingleCFCQKeyValueComparisonFilter) SingleCQKeyValueComparisonFilter(org.apache.phoenix.filter.SingleCQKeyValueComparisonFilter) Filter(org.apache.hadoop.hbase.filter.Filter) MultiCQKeyValueComparisonFilter(org.apache.phoenix.filter.MultiCQKeyValueComparisonFilter) EncodedColumnsUtil.isPossibleToUseEncodedCQFilter(org.apache.phoenix.util.EncodedColumnsUtil.isPossibleToUseEncodedCQFilter) MultiEncodedCQKeyValueComparisonFilter(org.apache.phoenix.filter.MultiEncodedCQKeyValueComparisonFilter) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) Expression(org.apache.phoenix.expression.Expression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) AndExpression(org.apache.phoenix.expression.AndExpression) SingleCQKeyValueComparisonFilter(org.apache.phoenix.filter.SingleCQKeyValueComparisonFilter) Scan(org.apache.hadoop.hbase.client.Scan) ImmutableStorageScheme(org.apache.phoenix.schema.PTable.ImmutableStorageScheme) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) MultiCFCQKeyValueComparisonFilter(org.apache.phoenix.filter.MultiCFCQKeyValueComparisonFilter) RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter)

Aggregations

Scan (org.apache.hadoop.hbase.client.Scan)1 Filter (org.apache.hadoop.hbase.filter.Filter)1 AndExpression (org.apache.phoenix.expression.AndExpression)1 Expression (org.apache.phoenix.expression.Expression)1 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)1 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)1 KeyValueExpressionVisitor (org.apache.phoenix.expression.visitor.KeyValueExpressionVisitor)1 MultiCFCQKeyValueComparisonFilter (org.apache.phoenix.filter.MultiCFCQKeyValueComparisonFilter)1 MultiCQKeyValueComparisonFilter (org.apache.phoenix.filter.MultiCQKeyValueComparisonFilter)1 MultiEncodedCQKeyValueComparisonFilter (org.apache.phoenix.filter.MultiEncodedCQKeyValueComparisonFilter)1 RowKeyComparisonFilter (org.apache.phoenix.filter.RowKeyComparisonFilter)1 SingleCFCQKeyValueComparisonFilter (org.apache.phoenix.filter.SingleCFCQKeyValueComparisonFilter)1 SingleCQKeyValueComparisonFilter (org.apache.phoenix.filter.SingleCQKeyValueComparisonFilter)1 PTable (org.apache.phoenix.schema.PTable)1 ImmutableStorageScheme (org.apache.phoenix.schema.PTable.ImmutableStorageScheme)1 QualifierEncodingScheme (org.apache.phoenix.schema.PTable.QualifierEncodingScheme)1 EncodedColumnsUtil.isPossibleToUseEncodedCQFilter (org.apache.phoenix.util.EncodedColumnsUtil.isPossibleToUseEncodedCQFilter)1