/** * Constructor that takes a set of {@link Filter}s and an operator. * @param operator Operator to process filter set with. * @param filters Set of row filters. */ public FilterList(final Operator operator, final List<Filter> filters) { if (operator == Operator.MUST_PASS_ALL) { filterListBase = new FilterListWithAND(filters); } else if (operator == Operator.MUST_PASS_ONE) { filterListBase = new FilterListWithOR(filters); } else { throw new IllegalArgumentException("Invalid operator: " + operator); } this.operator = operator; }
@Override public void addFilterLists(List<Filter> filters) { if (checkAndGetReversed(filters, isReversed()) != isReversed()) { throw new IllegalArgumentException("Filters in the list must have the same reversed flag"); } this.filters.addAll(filters); this.subFiltersIncludedCell.addAll(Collections.nCopies(filters.size(), true)); }
@Override public Cell getNextCellHint(Cell currentCell) throws IOException { if (isEmpty()) { return super.getNextCellHint(currentCell); } Cell maxHint = null; for (Filter filter : seekHintFilters) { if (filter.filterAllRemaining()) { continue; } Cell curKeyHint = filter.getNextCellHint(currentCell); if (maxHint == null) { maxHint = curKeyHint; continue; } if (this.compareCell(maxHint, curKeyHint) < 0) { maxHint = curKeyHint; } } return maxHint; }
@Override public ReturnCode filterCell(Cell c) throws IOException { if (isEmpty()) { return ReturnCode.INCLUDE; } ReturnCode rc = ReturnCode.INCLUDE; this.seekHintFilters.clear(); for (int i = 0, n = filters.size(); i < n; i++) { Filter filter = filters.get(i); if (filter.filterAllRemaining()) { return ReturnCode.NEXT_ROW; } ReturnCode localRC; localRC = filter.filterCell(c); if (localRC == ReturnCode.SEEK_NEXT_USING_HINT) { seekHintFilters.add(filter); } rc = mergeReturnCode(rc, localRC); // Only when rc is INCLUDE* case, we should pass the cell to the following sub-filters. // otherwise we may mess up the global state (such as offset, count..) in the following // sub-filters. (HBASE-20565) if (!isIncludeRelatedReturnCode(rc)) { return rc; } } if (!seekHintFilters.isEmpty()) { return ReturnCode.SEEK_NEXT_USING_HINT; } return rc; }
@Override public boolean filterAllRemaining() throws IOException { if (isEmpty()) { return super.filterAllRemaining(); } for (int i = 0, n = filters.size(); i < n; i++) { if (filters.get(i).filterAllRemaining()) { return true; } } return false; }
private boolean isIncludeRelatedReturnCode(ReturnCode rc) { return isInReturnCodes(rc, ReturnCode.INCLUDE, ReturnCode.INCLUDE_AND_NEXT_COL, ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW); }
@Override public ReturnCode filterCell(Cell c) throws IOException { if (isEmpty()) { return ReturnCode.INCLUDE; } ReturnCode rc = ReturnCode.INCLUDE; this.seekHintFilters.clear(); for (int i = 0, n = filters.size(); i < n; i++) { Filter filter = filters.get(i); if (filter.filterAllRemaining()) { return ReturnCode.NEXT_ROW; } ReturnCode localRC; localRC = filter.filterCell(c); rc = mergeReturnCode(rc, localRC); if (localRC == ReturnCode.SEEK_NEXT_USING_HINT) { seekHintFilters.add(filter); } } if (!seekHintFilters.isEmpty()) { return ReturnCode.SEEK_NEXT_USING_HINT; } return rc; }
@Override protected String formatLogFilters(List<Filter> logFilters) { return String.format("FilterList AND (%d/%d): %s", logFilters.size(), this.size(), logFilters.toString()); }
@Override public boolean equals(Object obj) { if (!(obj instanceof FilterListWithAND)) { return false; } if (this == obj) { return true; } FilterListWithAND f = (FilterListWithAND) obj; return this.filters.equals(f.getFilters()) && this.seekHintFilters.equals(f.seekHintFilters); }
@Override public ReturnCode filterCell(Cell c) throws IOException { if (isEmpty()) { return ReturnCode.INCLUDE; } ReturnCode rc = ReturnCode.INCLUDE; this.seekHintFilters.clear(); for (int i = 0, n = filters.size(); i < n; i++) { Filter filter = filters.get(i); if (filter.filterAllRemaining()) { return ReturnCode.NEXT_ROW; } ReturnCode localRC; localRC = filter.filterCell(c); if (localRC == ReturnCode.SEEK_NEXT_USING_HINT) { seekHintFilters.add(filter); } rc = mergeReturnCode(rc, localRC); // Only when rc is INCLUDE* case, we should pass the cell to the following sub-filters. // otherwise we may mess up the global state (such as offset, count..) in the following // sub-filters. (HBASE-20565) if (!isIncludeRelatedReturnCode(rc)) { return rc; } } if (!seekHintFilters.isEmpty()) { return ReturnCode.SEEK_NEXT_USING_HINT; } return rc; }
@Override public boolean filterRow() throws IOException { if (isEmpty()) { return super.filterRow(); } for (int i = 0, n = filters.size(); i < n; i++) { Filter filter = filters.get(i); if (filter.filterRow()) { return true; } } return false; }
return rc; case INCLUDE_AND_NEXT_COL: if (isInReturnCodes(rc, ReturnCode.INCLUDE, ReturnCode.INCLUDE_AND_NEXT_COL)) { return ReturnCode.INCLUDE_AND_NEXT_COL; if (isInReturnCodes(rc, ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW)) { return ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW; if (isInReturnCodes(rc, ReturnCode.SKIP, ReturnCode.NEXT_COL)) { return ReturnCode.NEXT_COL; if (isInReturnCodes(rc, ReturnCode.NEXT_ROW)) { return ReturnCode.NEXT_ROW; if (isInReturnCodes(rc, ReturnCode.INCLUDE, ReturnCode.INCLUDE_AND_NEXT_COL, ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW)) { return ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW; if (isInReturnCodes(rc, ReturnCode.SKIP, ReturnCode.NEXT_COL, ReturnCode.NEXT_ROW)) { return ReturnCode.NEXT_ROW; if (isInReturnCodes(rc, ReturnCode.INCLUDE, ReturnCode.SKIP)) { return ReturnCode.SKIP; if (isInReturnCodes(rc, ReturnCode.INCLUDE_AND_NEXT_COL, ReturnCode.NEXT_COL)) { return ReturnCode.NEXT_COL; if (isInReturnCodes(rc, ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW, ReturnCode.NEXT_ROW)) { return ReturnCode.NEXT_ROW;
@Override protected String formatLogFilters(List<Filter> logFilters) { return String.format("FilterList AND (%d/%d): %s", logFilters.size(), this.size(), logFilters.toString()); }
@Override public void addFilterLists(List<Filter> filters) { if (checkAndGetReversed(filters, isReversed()) != isReversed()) { throw new IllegalArgumentException("Filters in the list must have the same reversed flag"); } this.filters.addAll(filters); this.subFiltersIncludedCell.addAll(Collections.nCopies(filters.size(), true)); }
@Override public boolean filterRowKey(byte[] rowKey, int offset, int length) throws IOException { if (isEmpty()) { return super.filterRowKey(rowKey, offset, length); } boolean retVal = false; for (int i = 0, n = filters.size(); i < n; i++) { Filter filter = filters.get(i); if (filter.filterAllRemaining() || filter.filterRowKey(rowKey, offset, length)) { retVal = true; } } return retVal; }
@Override public Cell getNextCellHint(Cell currentCell) throws IOException { if (isEmpty()) { return super.getNextCellHint(currentCell); } Cell maxHint = null; for (Filter filter : seekHintFilters) { if (filter.filterAllRemaining()) { continue; } Cell curKeyHint = filter.getNextCellHint(currentCell); if (maxHint == null) { maxHint = curKeyHint; continue; } if (this.compareCell(maxHint, curKeyHint) < 0) { maxHint = curKeyHint; } } return maxHint; } }
private boolean isIncludeRelatedReturnCode(ReturnCode rc) { return isInReturnCodes(rc, ReturnCode.INCLUDE, ReturnCode.INCLUDE_AND_NEXT_COL, ReturnCode.INCLUDE_AND_SEEK_NEXT_ROW); }
@Override protected String formatLogFilters(List<Filter> logFilters) { return String.format("FilterList AND (%d/%d): %s", logFilters.size(), this.size(), logFilters.toString()); }
/** * Constructor that takes a set of {@link Filter}s and an operator. * @param operator Operator to process filter set with. * @param filters Set of row filters. */ public FilterList(final Operator operator, final List<Filter> filters) { if (operator == Operator.MUST_PASS_ALL) { filterListBase = new FilterListWithAND(filters); } else if (operator == Operator.MUST_PASS_ONE) { filterListBase = new FilterListWithOR(filters); } else { throw new IllegalArgumentException("Invalid operator: " + operator); } this.operator = operator; }
@Override public void addFilterLists(List<Filter> filters) { if (checkAndGetReversed(filters, isReversed()) != isReversed()) { throw new IllegalArgumentException("Filters in the list must have the same reversed flag"); } this.filters.addAll(filters); this.subFiltersIncludedCell.addAll(Collections.nCopies(filters.size(), true)); }