Java Code Examples for org.apache.hadoop.hbase.filter.FilterList#getFilters()

The following examples show how to use org.apache.hadoop.hbase.filter.FilterList#getFilters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RowCountVisitor.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public static Filter stripSkipScanFilter(Filter filter) {
    if (filter == null) {
        return null;
    }
    if (!(filter instanceof FilterList)) {
        return filter instanceof BooleanExpressionFilter ? filter : null;
    }
    FilterList filterList = (FilterList) filter;
    if (filterList.getOperator() != FilterList.Operator.MUST_PASS_ALL) {
        return filter;
    }
    List<Filter> list = new ArrayList<>();
    for (Filter f : filterList.getFilters()) {
        Filter stripped = stripSkipScanFilter(f);
        if (stripped != null) {
            list.add(stripped);
        }
    }
    return list.isEmpty() ? null : (list.size() == 1 ? list.get(0) : new FilterList(FilterList.Operator.MUST_PASS_ALL, list));
}
 
Example 2
Source File: ScanUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static void setRowKeyOffset(Scan scan, int offset) {
    Filter filter = scan.getFilter();
    if (filter == null) {
        return;
    }
    if (filter instanceof FilterList) {
        FilterList filterList = (FilterList)filter;
        for (Filter childFilter : filterList.getFilters()) {
            setRowKeyOffset(childFilter, offset);
        }
    } else {
        setRowKeyOffset(filter, offset);
    }
}
 
Example 3
Source File: StatementHintsCompilationTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static boolean usingSkipScan(Scan scan) {
    Filter filter = scan.getFilter();
    if (filter instanceof FilterList) {
        FilterList filterList = (FilterList) filter;
        for (Filter childFilter : filterList.getFilters()) {
            if (childFilter instanceof SkipScanFilter) {
                return true;
            }
        }
        return false;
    }
    return filter instanceof SkipScanFilter;
}
 
Example 4
Source File: TestHBaseStorageFiltering.java    From spork with Apache License 2.0 5 votes vote down vote up
private List<Filter> assertFilterList(Filter filter, FilterList.Operator operator, int size) {
    assertTrue("Filter is not a FilterList: " + filter.getClass().getSimpleName(),
            filter instanceof FilterList);
    FilterList filterList = (FilterList)filter;
    assertEquals("Unexpected operator", operator, filterList.getOperator());
    assertEquals("Unexpected filter list size", size, filterList.getFilters().size());
    return filterList.getFilters();
}
 
Example 5
Source File: ScanUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static void setRowKeyOffset(Scan scan, int offset) {
    Filter filter = scan.getFilter();
    if (filter == null) {
        return;
    }
    if (filter instanceof FilterList) {
        FilterList filterList = (FilterList)filter;
        for (Filter childFilter : filterList.getFilters()) {
            setRowKeyOffset(childFilter, offset);
        }
    } else {
        setRowKeyOffset(filter, offset);
    }
}
 
Example 6
Source File: StatementHintsCompilationTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static boolean usingSkipScan(Scan scan) {
    Filter filter = scan.getFilter();
    if (filter instanceof FilterList) {
        FilterList filterList = (FilterList) filter;
        for (Filter childFilter : filterList.getFilters()) {
            if (childFilter instanceof SkipScanFilter) {
                return true;
            }
        }
        return false;
    }
    return filter instanceof SkipScanFilter;
}
 
Example 7
Source File: StatementHintsCompilationTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static boolean usingSkipScan(Scan scan) {
    Filter filter = scan.getFilter();
    if (filter instanceof FilterList) {
        FilterList filterList = (FilterList) filter;
        for (Filter childFilter : filterList.getFilters()) {
            if (childFilter instanceof SkipScanFilter) {
                return true;
            }
        }
        return false;
    }
    return filter instanceof SkipScanFilter;
}
 
Example 8
Source File: HBaseUtils.java    From pxf with Apache License 2.0 4 votes vote down vote up
/**
 * get StringBuilder with print according to given {@link FilterList}
 * 
 * @param result as {@link StringBuilder}
 * @param filterList {@link FilterList} with HBase filters
 */
public static void getFilterListPrint(StringBuilder result, FilterList filterList) {

	if (filterList == null || filterList.getFilters().size() == 0) {
		return;
	}

	if (result == null) {
		result = new StringBuilder();
	}

	List<Filter> list = filterList.getFilters();

	Operator operator = filterList.getOperator();
	String operatorString = (operator.equals(Operator.MUST_PASS_ALL)) ? " AND " : " OR ";

	// open current filter list
	result.append("[");

	int listIndex = 0;

	// go over each filter in the list
	for (Filter filter : list) {

		// if current filter is a FilterList, call the method again with it
		if (filter instanceof FilterList) {
			getFilterListPrint(result, (FilterList) filter);
		} else {

			// append filter to result
			result.append("(" + filter + ")");

			// if end of list and not FilterList, close the current list
			if (listIndex == list.size() - 1) {
				result.append("]");
			}
		}

		// if still not the end of list put the operator
		if (listIndex != list.size() - 1) {
			result.append(operatorString);
		}

		listIndex++;
	}
}
 
Example 9
Source File: SkipScanQueryIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Test
public void testOrWithMixedOrderPKs() throws Exception {
    String tableName = generateUniqueName();
    try (Connection conn = DriverManager.getConnection(getUrl())) {
        conn.setAutoCommit(true);
        Statement stmt = conn.createStatement();

        stmt.execute("CREATE TABLE " + tableName +
                " (COL1 VARCHAR, COL2 VARCHAR CONSTRAINT PK PRIMARY KEY (COL1 DESC, COL2)) ");

        // this is the order the rows will be stored on disk
        stmt.execute("UPSERT INTO " + tableName + " (COL1, COL2) VALUES ('8', 'a')");
        stmt.execute("UPSERT INTO " + tableName + " (COL1, COL2) VALUES ('6', 'a')");
        stmt.execute("UPSERT INTO " + tableName + " (COL1, COL2) VALUES ('23', 'b')");
        stmt.execute("UPSERT INTO " + tableName + " (COL1, COL2) VALUES ('23', 'bb')");
        stmt.execute("UPSERT INTO " + tableName + " (COL1, COL2) VALUES ('2', 'a')");
        stmt.execute("UPSERT INTO " + tableName + " (COL1, COL2) VALUES ('17', 'a')");


        // test values in the skip scan filter which are prefixes of another value, eg 1,12 and 2,23
        String sql = "select COL1, COL2 from " + tableName + " where COL1='1' OR COL1='2' OR COL1='3' OR COL1='4' " +
                "OR COL1='5' OR COL1='6' OR COL1='8' OR COL1='17' OR COL1='12' OR COL1='23'";

        ResultSet rs = stmt.executeQuery(sql);
        assertTrue(rs.next());

        QueryPlan plan = stmt.unwrap(PhoenixStatement.class).getQueryPlan();
        assertEquals("Expected a single scan ", 1, plan.getScans().size());
        assertEquals("Expected a single scan ", 1, plan.getScans().get(0).size());
        Scan scan = plan.getScans().get(0).get(0);
        FilterList filterList = (FilterList)scan.getFilter();
        boolean skipScanFilterFound = false;
        for (Filter f : filterList.getFilters()) {
            if (f instanceof SkipScanFilter) {
                skipScanFilterFound = true;
                SkipScanFilter skipScanFilter = (SkipScanFilter) f;
                assertEquals("Expected a single slot ", skipScanFilter.getSlots().size(), 1);
                assertEquals("Number of key ranges should match number of or filters ",
                        skipScanFilter.getSlots().get(0).size(), 10);
            }
        }
        assertTrue("Should use skip scan filter", skipScanFilterFound);

        assertEquals("8", rs.getString(1));
        assertEquals("a", rs.getString(2));
        assertTrue(rs.next());
        assertEquals("6", rs.getString(1));
        assertEquals("a", rs.getString(2));
        assertTrue(rs.next());
        assertEquals("23", rs.getString(1));
        assertEquals("b", rs.getString(2));
        assertTrue(rs.next());
        assertEquals("23", rs.getString(1));
        assertEquals("bb", rs.getString(2));
        assertTrue(rs.next());
        assertEquals("2", rs.getString(1));
        assertEquals("a", rs.getString(2));
        assertTrue(rs.next());
        assertEquals("17", rs.getString(1));
        assertEquals("a", rs.getString(2));
        assertFalse(rs.next());
    }
}