Search in sources :

Example 1 with BooleanExpressionFilter

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

the class ScanUtil method setRowKeyOffset.

private static void setRowKeyOffset(Filter filter, int offset) {
    if (filter instanceof BooleanExpressionFilter) {
        BooleanExpressionFilter boolFilter = (BooleanExpressionFilter) filter;
        IndexUtil.setRowKeyExpressionOffset(boolFilter.getExpression(), offset);
    } else if (filter instanceof SkipScanFilter) {
        SkipScanFilter skipScanFilter = (SkipScanFilter) filter;
        skipScanFilter.setOffset(offset);
    } else if (filter instanceof DistinctPrefixFilter) {
        DistinctPrefixFilter prefixFilter = (DistinctPrefixFilter) filter;
        prefixFilter.setOffset(offset);
    }
}
Also used : DistinctPrefixFilter(org.apache.phoenix.filter.DistinctPrefixFilter) BooleanExpressionFilter(org.apache.phoenix.filter.BooleanExpressionFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter)

Example 2 with BooleanExpressionFilter

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

the class HavingCompilerTest method compileStatement.

private static Expressions compileStatement(String query, List<Object> binds) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    TestUtil.bindParams(pstmt, binds);
    QueryPlan plan = pstmt.compileQuery();
    assertTrue(plan instanceof AggregatePlan);
    Filter filter = plan.getContext().getScan().getFilter();
    assertTrue(filter == null || filter instanceof BooleanExpressionFilter);
    BooleanExpressionFilter boolFilter = (BooleanExpressionFilter) filter;
    AggregatePlan aggPlan = (AggregatePlan) plan;
    return new Expressions(boolFilter == null ? null : boolFilter.getExpression(), aggPlan.getHaving());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) BooleanExpressionFilter(org.apache.phoenix.filter.BooleanExpressionFilter) Filter(org.apache.hadoop.hbase.filter.Filter) AggregatePlan(org.apache.phoenix.execute.AggregatePlan) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) BooleanExpressionFilter(org.apache.phoenix.filter.BooleanExpressionFilter)

Example 3 with BooleanExpressionFilter

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

the class ExplainTable method explain.

protected void explain(String prefix, List<String> planSteps) {
    StringBuilder buf = new StringBuilder(prefix);
    ScanRanges scanRanges = context.getScanRanges();
    Scan scan = context.getScan();
    if (scan.getConsistency() != Consistency.STRONG) {
        buf.append("TIMELINE-CONSISTENCY ");
    }
    if (hint.hasHint(Hint.SMALL)) {
        buf.append(Hint.SMALL).append(" ");
    }
    if (OrderBy.REV_ROW_KEY_ORDER_BY.equals(orderBy)) {
        buf.append("REVERSE ");
    }
    if (scanRanges.isEverything()) {
        buf.append("FULL SCAN ");
    } else {
        explainSkipScan(buf);
    }
    buf.append("OVER ").append(tableRef.getTable().getPhysicalName().getString());
    if (!scanRanges.isPointLookup()) {
        appendKeyRanges(buf);
    }
    planSteps.add(buf.toString());
    if (context.getScan() != null && tableRef.getTable().getRowTimestampColPos() != -1) {
        TimeRange range = context.getScan().getTimeRange();
        planSteps.add("    ROW TIMESTAMP FILTER [" + range.getMin() + ", " + range.getMax() + ")");
    }
    PageFilter pageFilter = null;
    FirstKeyOnlyFilter firstKeyOnlyFilter = null;
    BooleanExpressionFilter whereFilter = null;
    DistinctPrefixFilter distinctFilter = null;
    Iterator<Filter> filterIterator = ScanUtil.getFilterIterator(scan);
    if (filterIterator.hasNext()) {
        do {
            Filter filter = filterIterator.next();
            if (filter instanceof FirstKeyOnlyFilter) {
                firstKeyOnlyFilter = (FirstKeyOnlyFilter) filter;
            } else if (filter instanceof PageFilter) {
                pageFilter = (PageFilter) filter;
            } else if (filter instanceof BooleanExpressionFilter) {
                whereFilter = (BooleanExpressionFilter) filter;
            } else if (filter instanceof DistinctPrefixFilter) {
                distinctFilter = (DistinctPrefixFilter) filter;
            }
        } while (filterIterator.hasNext());
    }
    if (whereFilter != null) {
        planSteps.add("    SERVER FILTER BY " + (firstKeyOnlyFilter == null ? "" : "FIRST KEY ONLY AND ") + whereFilter.toString());
    } else if (firstKeyOnlyFilter != null) {
        planSteps.add("    SERVER FILTER BY FIRST KEY ONLY");
    }
    if (distinctFilter != null) {
        planSteps.add("    SERVER DISTINCT PREFIX FILTER OVER " + groupBy.getExpressions().toString());
    }
    if (!orderBy.getOrderByExpressions().isEmpty() && groupBy.isEmpty()) {
        // with GROUP BY, sort happens client-side
        planSteps.add("    SERVER" + (limit == null ? "" : " TOP " + limit + " ROW" + (limit == 1 ? "" : "S")) + " SORTED BY " + orderBy.getOrderByExpressions().toString());
    } else {
        if (offset != null) {
            planSteps.add("    SERVER OFFSET " + offset);
        }
        if (pageFilter != null) {
            planSteps.add("    SERVER " + pageFilter.getPageSize() + " ROW LIMIT");
        }
    }
    Integer groupByLimit = null;
    byte[] groupByLimitBytes = scan.getAttribute(BaseScannerRegionObserver.GROUP_BY_LIMIT);
    if (groupByLimitBytes != null) {
        groupByLimit = (Integer) PInteger.INSTANCE.toObject(groupByLimitBytes);
    }
    groupBy.explain(planSteps, groupByLimit);
    if (scan.getAttribute(BaseScannerRegionObserver.SPECIFIC_ARRAY_INDEX) != null) {
        planSteps.add("    SERVER ARRAY ELEMENT PROJECTION");
    }
}
Also used : PInteger(org.apache.phoenix.schema.types.PInteger) TimeRange(org.apache.hadoop.hbase.io.TimeRange) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) BooleanExpressionFilter(org.apache.phoenix.filter.BooleanExpressionFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) DistinctPrefixFilter(org.apache.phoenix.filter.DistinctPrefixFilter) PageFilter(org.apache.hadoop.hbase.filter.PageFilter) Filter(org.apache.hadoop.hbase.filter.Filter) Scan(org.apache.hadoop.hbase.client.Scan) PageFilter(org.apache.hadoop.hbase.filter.PageFilter) DistinctPrefixFilter(org.apache.phoenix.filter.DistinctPrefixFilter) ScanRanges(org.apache.phoenix.compile.ScanRanges) BooleanExpressionFilter(org.apache.phoenix.filter.BooleanExpressionFilter)

Aggregations

BooleanExpressionFilter (org.apache.phoenix.filter.BooleanExpressionFilter)3 Filter (org.apache.hadoop.hbase.filter.Filter)2 DistinctPrefixFilter (org.apache.phoenix.filter.DistinctPrefixFilter)2 Scan (org.apache.hadoop.hbase.client.Scan)1 FirstKeyOnlyFilter (org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter)1 PageFilter (org.apache.hadoop.hbase.filter.PageFilter)1 TimeRange (org.apache.hadoop.hbase.io.TimeRange)1 ScanRanges (org.apache.phoenix.compile.ScanRanges)1 AggregatePlan (org.apache.phoenix.execute.AggregatePlan)1 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)1 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)1 PhoenixPreparedStatement (org.apache.phoenix.jdbc.PhoenixPreparedStatement)1 PInteger (org.apache.phoenix.schema.types.PInteger)1